]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/dialogs/interaction.cpp
Use vlc_object_lock and vlc_object_unlock
[vlc] / modules / gui / wxwidgets / dialogs / interaction.cpp
index b2b6acd7d2b96d48288d7679b3c3996d106b05de..28f8d8b4141cd96a682f716d4a2bfd884b3a4498 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,8 +28,6 @@
 
 #include <wx/statline.h>
 
-#define FREE( i ) { if( i ) free( i ); i = NULL; }
-
 /*****************************************************************************
  * Event Table.
  *****************************************************************************/
@@ -41,11 +39,12 @@ enum
      NoShow_Event
 };
 
-BEGIN_EVENT_TABLE( InteractionDialog, wxFrame )
+BEGIN_EVENT_TABLE( InteractionDialog, wxDialog)
     EVT_CLOSE( InteractionDialog::OnClose )
     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 )
@@ -57,8 +56,9 @@ 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 ) )
 {
+#if 0
     /* Initializations */
     p_intf = _p_intf;
     p_dialog = _p_dialog;
@@ -69,7 +69,7 @@ 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 );
@@ -80,6 +80,7 @@ InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
 
     b_noshow = false;
     Render();
+#endif
 }
 
 InteractionDialog::~InteractionDialog()
@@ -88,6 +89,7 @@ InteractionDialog::~InteractionDialog()
 
 void InteractionDialog::Update( )
 {
+#if 0
     widgets_panel->DestroyChildren();
     /* FIXME: Needed for the spacer */
     buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
@@ -98,21 +100,23 @@ void InteractionDialog::Update( )
     {
         Show();
     }
+#endif
 }
 
 /// \todo Dirty - Clean that up
 void InteractionDialog::Render()
 {
+#if 0
     wxStaticText *label;
     wxTextCtrl   *input;
     wxGauge      *gauge;
 
 
-    if( p_dialog->i_id == DIALOG_ERRORS )
+    if( p_dialog->i_flags == DIALOG_BLOCKING_ERROR || p_dialog->i_flags == DIALOG_NONBLOCKING_ERROR )
     {
         wxTextCtrl *errors ; // Special case
         label = new wxStaticText( widgets_panel, -1,
-          wxU( _("The following errors happened. More details might be "
+          wxU( _("The following errors occurred. More details might be "
                  "available in the Messages window.") ) );
         errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
                          wxDefaultPosition, wxDefaultSize,
@@ -151,6 +155,7 @@ void InteractionDialog::Render()
                 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 ) );
@@ -164,45 +169,43 @@ void InteractionDialog::Render()
     }
 
     //-------------- Buttons ------------------
-    if( p_dialog->i_flags & DIALOG_OK_CANCEL )
-    {
-        wxButton *ok = new wxButton( buttons_panel,
-                                     wxID_OK, wxU( _("OK") ) );
-        wxButton *cancel = new wxButton( buttons_panel,
-                                         wxID_CANCEL, wxU( _("Cancel") ) );
-        buttons_sizer->Add( ok, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
-        buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
-    }
-    else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
+    if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
     {
         wxButton *yes = new wxButton( buttons_panel,
-                                      wxID_YES, wxU( _("Yes") ) );
+                                      wxID_YES, wxU( _("&Yes") ) );
         wxButton *no = new wxButton( buttons_panel,
-                                     wxID_NO, wxU( _("No") ) );
+                                     wxID_NO, wxU( _("&No") ) );
         wxButton *cancel = new wxButton( buttons_panel,
-                                         wxID_CANCEL, wxU( _("Cancel") ) );
-        buttons_sizer->Add( yes, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
-        buttons_sizer->Add( no, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
-        buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
+                                         wxID_CANCEL, wxU( _("&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") ) );
+                      NoShow_Event, wxU( _("Don't show further errors") ) );
         noshow->SetValue( b_noshow );
         wxButton *clear = new wxButton( buttons_panel,
-                                        wxID_CLEAR, wxU( _("Clear") ) );
-        buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_LEFT, 5 );
+                                        wxID_CLEAR, wxU( _("&Clear") ) );
+        wxButton *close = new wxButton( buttons_panel, wxID_CLOSE,
+                                         wxU( _("&Close") ) );
+        close->SetDefault();
+        buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT|
+                                       wxLEFT | wxALIGN_LEFT, 5 );
         buttons_sizer->Add( 0, 0, 1 );
-        buttons_sizer->Add( clear , 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_RIGHT, 5 );
-
+        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->Layout();
+    buttons_sizer->Realize();
     buttons_panel->SetSizerAndFit( buttons_sizer );
     main_sizer->Layout();
     SetSizerAndFit( main_sizer );
+#endif
 }
 
 /*****************************************************************************
@@ -230,23 +233,26 @@ void InteractionDialog::OnOkYes( wxCommandEvent& event )
 
 void InteractionDialog::OnClear( wxCommandEvent& event )
 {
+#if 0
     int i;
-    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
+    vlc_object_lock( p_dialog->p_interaction );
     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 );
+        FREENULL( p_widget->psz_text );
+        FREENULL( 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_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 );
+    vlc_object_unlock( p_dialog->p_interaction );
     Render();
+#endif
 }
 
 void InteractionDialog::OnNoShow( wxCommandEvent& event )
@@ -256,18 +262,18 @@ void InteractionDialog::OnNoShow( wxCommandEvent& event )
 
 void InteractionDialog::Finish( int i_ret )
 {
-    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
+#if 0
+    vlc_object_lock( p_dialog->p_interaction );
     vector<InputWidget>::iterator it = input_widgets.begin();
     while ( it < input_widgets.end() )
     {
         if( (*it).i_type == WIDGET_INPUT_TEXT )
-            (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str();
+            (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str(wxConvUTF8));
         it++;
     }
     Hide();
     p_dialog->i_status = ANSWERED_DIALOG;
     p_dialog->i_return = i_ret;
-    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
+    vlc_object_unlock( p_dialog->p_interaction );
+#endif
 }
-
-#undef FREE