]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/dialogs/interaction.cpp
* : svn:keywords
[vlc] / modules / gui / wxwidgets / dialogs / interaction.cpp
index b2c4e1516cd01e013e3b7cbb7c4eaac51f6df97d..7c8f890c0ab1ad4f2c047d5d575f0a96032470bb 100644 (file)
@@ -2,9 +2,9 @@
  * interaction.cpp: wxWidgets handling of interaction dialogs
  *****************************************************************************
  * Copyright (C) 2000-2004 the VideoLAN team
- * $Id: bookmarks.cpp 13106 2005-11-02 19:20:34Z zorglub $
+ * $Id$
  *
- * Authors: Clément Stenac <zorglub@videolan.org>
+ * Authors: Clément Stenac <zorglub@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -28,6 +28,8 @@
 
 #include <wx/statline.h>
 
+#define FREE( i ) { if( i ) free( i ); i = NULL; }
+
 /*****************************************************************************
  * Event Table.
  *****************************************************************************/
 /* IDs for the controls and the menu commands */
 enum
 {
-     OkYes_Event,
      No_Event,
-     Cancel_Event
+     NoShow_Event
 };
 
-BEGIN_EVENT_TABLE( InteractionDialog, wxFrame)
+BEGIN_EVENT_TABLE( InteractionDialog, wxDialog)
     EVT_CLOSE( InteractionDialog::OnClose )
-    EVT_BUTTON( OkYes_Event, InteractionDialog::OnOkYes )
-    EVT_BUTTON( Cancel_Event, InteractionDialog::OnCancel)
-    EVT_BUTTON( No_Event, InteractionDialog::OnNo )
+    EVT_BUTTON( wxID_OK, InteractionDialog::OnOkYes )
+    EVT_BUTTON( wxID_YES, InteractionDialog::OnOkYes )
+    EVT_BUTTON( wxID_CANCEL, InteractionDialog::OnCancel)
+    EVT_BUTTON( wxID_CLOSE, InteractionDialog::OnCancel)
+    EVT_BUTTON( wxID_NO, InteractionDialog::OnNo )
+    EVT_BUTTON( wxID_CLEAR, InteractionDialog::OnClear )
+    EVT_CHECKBOX( NoShow_Event, InteractionDialog::OnNoShow )
 END_EVENT_TABLE()
 
 /*****************************************************************************
@@ -53,7 +58,7 @@ END_EVENT_TABLE()
 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
                                       wxWindow *p_parent,
                                       interaction_dialog_t *_p_dialog )
-  : wxFrame( p_parent, -1, wxU( _p_dialog->psz_title ) )
+  : wxDialog( p_parent, -1, wxU( _p_dialog->psz_title ) )
 {
     /* Initializations */
     p_intf = _p_intf;
@@ -65,15 +70,16 @@ InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
     widgets_panel->SetSizer( widgets_sizer );
 
     buttons_panel = new wxPanel( this, -1 );
-    buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
+    buttons_sizer = new wxStdDialogButtonSizer;
     buttons_panel->SetSizer( buttons_sizer );
 
     main_sizer = new wxBoxSizer( wxVERTICAL );
-    main_sizer->Add( widgets_panel, 0, wxEXPAND | wxALL, 5 );
+    main_sizer->Add( widgets_panel, 1, wxEXPAND | wxALL, 5 );
     main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND  );
     main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
     SetSizer( main_sizer );
 
+    b_noshow = false;
     Render();
 }
 
@@ -84,59 +90,120 @@ InteractionDialog::~InteractionDialog()
 void InteractionDialog::Update( )
 {
     widgets_panel->DestroyChildren();
+    /* FIXME: Needed for the spacer */
+    buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
     buttons_panel->DestroyChildren();
     input_widgets.clear();
     Render();
-    Show();
+    if( b_noshow == false )
+    {
+        Show();
+    }
 }
 
 /// \todo Dirty - Clean that up
 void InteractionDialog::Render()
 {
     wxStaticText *label;
-    wxTextCtrl *input;
+    wxTextCtrl   *input;
+    wxGauge      *gauge;
 
-    //-------------- Widgets ------------------
-    for( int i = 0 ; i< p_dialog->i_widgets; i++ )
+
+    if( p_dialog->i_id == DIALOG_ERRORS )
     {
-        user_widget_t* p_widget = p_dialog->pp_widgets[i];
-        /// \todo Merge cleanly with preferences widgets
-        switch( p_widget->i_type )
+        wxTextCtrl *errors ; // Special case
+        label = new wxStaticText( widgets_panel, -1,
+          wxU( _("The following errors occurred. More details might be "
+                 "available in the Messages window.") ) );
+        errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
+                         wxDefaultPosition, wxDefaultSize,
+                         wxTE_MULTILINE | wxTE_READONLY );
+        for( int i = 0 ; i< p_dialog->i_widgets; i++ )
         {
-        case WIDGET_TEXT:
-            label = new wxStaticText( widgets_panel, -1,
-                                      wxU( p_widget->psz_text ) );
-            widgets_sizer->Add( label );
-            break;
-        case WIDGET_INPUT_TEXT:
-            label = new wxStaticText( widgets_panel, -1,
-                                      wxU( p_widget->psz_text ) );
-            input = new wxTextCtrl( widgets_panel, -1 );
-            widgets_sizer->Add( label );
-            widgets_sizer->Add( input );
-
-            InputWidget widget;
-            widget.control = input;
-            widget.val = &p_widget->val;
-            input_widgets.push_back( widget );
+            (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
+                           wxU( "\n" ) ;
+        }
+        widgets_sizer->Add( label );
+        widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
+    }
+    else
+    {
+        //-------------- Widgets ------------------
+        for( int i = 0 ; i< p_dialog->i_widgets; i++ )
+        {
+            user_widget_t* p_widget = p_dialog->pp_widgets[i];
+            /// \todo Merge cleanly with preferences widgets
+            switch( p_widget->i_type )
+            {
+            case WIDGET_TEXT:
+                label = new wxStaticText( widgets_panel, -1,
+                                           wxU( p_widget->psz_text ) );
+                widgets_sizer->Add( label );
+                break;
+            case WIDGET_INPUT_TEXT:
+                label = new wxStaticText( widgets_panel, -1,
+                                           wxU( p_widget->psz_text ) );
+                input = new wxTextCtrl( widgets_panel, -1 );
+                widgets_sizer->Add( label , 0, 0, 0);
+                widgets_sizer->Add( input, 0, wxEXPAND , 0 );
+
+                InputWidget widget;
+                widget.control = input;
+                widget.val = &p_widget->val;
+                widget.i_type = WIDGET_INPUT_TEXT;
+                input_widgets.push_back( widget );
+                break;
+            case WIDGET_PROGRESS:
+                label = new wxStaticText(widgets_panel, -1,
+                                    wxU( p_widget->psz_text ) );
+                gauge = new wxGauge( widgets_panel, -1, 100,
+                                     wxDefaultPosition, wxDefaultSize );
+                widgets_sizer->Add( label , 0, 0, 0);
+                widgets_sizer->Add( gauge, 0, wxEXPAND , 0 );
+                gauge->SetValue( (int)(p_widget->val.f_float ) );
+            }
         }
     }
-    widgets_sizer->Layout();
-    widgets_panel->SetSizerAndFit( widgets_sizer );
-    main_sizer->Layout();
-    SetSizerAndFit( main_sizer );
 
     //-------------- Buttons ------------------
     if( p_dialog->i_flags & DIALOG_OK_CANCEL )
     {
-        wxButton *ok = new wxButton( buttons_panel,
-                                     OkYes_Event, wxU( _("OK") ) );
-        wxButton *cancel = new wxButton( buttons_panel,
-                                         Cancel_Event, wxU( _("Cancel") ) );
-        buttons_sizer->Add( ok, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
-        buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
+        wxButton *ok = new wxButton( buttons_panel, wxID_OK );
+        wxButton *cancel = new wxButton( buttons_panel, wxID_CANCEL );
+        buttons_sizer->AddButton( ok );
+        buttons_sizer->AddButton( cancel );
     }
-
+    else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
+    {
+        wxButton *yes = new wxButton( buttons_panel, wxID_YES );
+        wxButton *no = new wxButton( buttons_panel, wxID_NO );
+        wxButton *cancel = new wxButton( buttons_panel, wxID_CANCEL );
+        buttons_sizer->AddButton( yes );
+        buttons_sizer->AddButton( no );
+        buttons_sizer->AddButton( cancel );
+    }
+    else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
+    {
+        wxCheckBox *noshow = new wxCheckBox( buttons_panel,
+                      NoShow_Event, wxU( _("Don't show further errors") ) );
+        noshow->SetValue( b_noshow );
+        wxButton *clear = new wxButton( buttons_panel, wxID_CLEAR );
+        wxButton *close = new wxButton( buttons_panel, wxID_CLOSE );
+        close->SetDefault();
+        buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT|
+                                       wxLEFT | wxALIGN_LEFT, 5 );
+        buttons_sizer->Add( 0, 0, 1 );
+        buttons_sizer->AddButton( clear );
+        buttons_sizer->SetNegativeButton( clear );
+        buttons_sizer->AddButton( close );
+        buttons_sizer->SetAffirmativeButton( close );
+    }
+    widgets_sizer->Layout();
+    widgets_panel->SetSizerAndFit( widgets_sizer );
+    buttons_sizer->Realize();
+    buttons_panel->SetSizerAndFit( buttons_sizer );
+    main_sizer->Layout();
+    SetSizerAndFit( main_sizer );
 }
 
 /*****************************************************************************
@@ -162,17 +229,47 @@ void InteractionDialog::OnOkYes( wxCommandEvent& event )
     Finish( DIALOG_OK_YES );
 }
 
+void InteractionDialog::OnClear( wxCommandEvent& event )
+{
+    int i;
+    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
+    for( i = p_dialog->i_widgets - 1 ; i >= 0 ; i-- )
+    {
+        user_widget_t *p_widget = p_dialog->pp_widgets[i];
+        FREE( p_widget->psz_text );
+        FREE( p_widget->val.psz_string );
+        REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, i );
+        free( p_widget );
+    }
+    widgets_panel->DestroyChildren();
+    /* FIXME: Needed for the spacer */
+    buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );
+    buttons_sizer->Remove( 3 );
+    buttons_panel->DestroyChildren();
+    input_widgets.clear();
+    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
+    Render();
+}
+
+void InteractionDialog::OnNoShow( wxCommandEvent& event )
+{
+     b_noshow = event.IsChecked();
+}
+
 void InteractionDialog::Finish( int i_ret )
 {
+    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
     vector<InputWidget>::iterator it = input_widgets.begin();
     while ( it < input_widgets.end() )
     {
-        (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str() );
+        if( (*it).i_type == WIDGET_INPUT_TEXT )
+            (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str());
         it++;
     }
     Hide();
-    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
     p_dialog->i_status = ANSWERED_DIALOG;
     p_dialog->i_return = i_ret;
     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
 }
+
+#undef FREE