]> git.sesse.net Git - vlc/commitdiff
Beginning of a WX implementation
authorClément Stenac <zorglub@videolan.org>
Sun, 11 Dec 2005 16:08:23 +0000 (16:08 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 11 Dec 2005 16:08:23 +0000 (16:08 +0000)
Dirty currently ...

modules/gui/wxwidgets/Modules.am
modules/gui/wxwidgets/dialogs.cpp
modules/gui/wxwidgets/dialogs/interaction.cpp [new file with mode: 0644]
modules/gui/wxwidgets/dialogs/interaction.hpp [new file with mode: 0644]
modules/gui/wxwidgets/dialogs/playlist.cpp
modules/gui/wxwidgets/interface.cpp

index ed94845d2238c30dd3f86a8c9e99b0f5a32feb1b..4c12c06f38f19c21fd6591db288339e6c9529c2f 100644 (file)
@@ -12,6 +12,7 @@ SOURCES_wxwidgets = \
        playlist_manager.cpp \
        dialogs.cpp \
        dialogs/open.cpp \
+       dialogs/interaction.cpp \
        dialogs/streamout.cpp \
        dialogs/wizard.cpp \
        dialogs/messages.cpp \
@@ -52,6 +53,7 @@ EXTRA_DIST += \
        dialogs/vlm/vlm_slider_manager.hpp \
        dialogs/vlm/vlm_wrapper.hpp \
        dialogs/playlist.hpp \
+       dialogs/interaction.hpp \
        dialogs/open.hpp \
        dialogs/messages.hpp \
        dialogs/iteminfo.hpp \
index e9c602d14b37e2aa0d6a0195e969a1c21cee89ed..e765dd9838dbc87465447af67469d9e2ed8985da 100644 (file)
@@ -45,6 +45,7 @@
 #include "dialogs/iteminfo.hpp"
 #include "dialogs/preferences.hpp"
 #include "dialogs/messages.hpp"
+#include "dialogs/interaction.hpp"
 #include "interface.hpp"
 
 /* include the icon graphic */
@@ -64,6 +65,7 @@ private:
     /* Event handlers (these functions should _not_ be virtual) */
     void OnUpdateVLC( wxCommandEvent& event );
     void OnVLM( wxCommandEvent& event );
+    void OnInteraction( wxCommandEvent& event );
     void OnExit( wxCommandEvent& event );
     void OnPlaylist( wxCommandEvent& event );
     void OnMessages( wxCommandEvent& event );
@@ -146,6 +148,8 @@ BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
                 DialogsProvider::OnUpdateVLC)
     EVT_COMMAND(INTF_DIALOG_VLM, wxEVT_DIALOG,
                 DialogsProvider::OnVLM)
+    EVT_COMMAND( INTF_DIALOG_INTERACTION, wxEVT_DIALOG,
+                DialogsProvider::OnInteraction )
 END_EVENT_TABLE()
 
 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
@@ -531,3 +535,39 @@ void DialogsProvider::OnVLM( wxCommandEvent& WXUNUSED(event) )
         p_vlm_dialog->Show( !p_vlm_dialog->IsShown() );
     }
 }
+
+void DialogsProvider::OnInteraction( wxCommandEvent& event )
+{
+    intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
+    interaction_dialog_t *p_dialog;
+    InteractionDialog *p_wxdialog;
+
+    if( p_arg == NULL )
+    {
+        msg_Dbg( p_intf, "OnInteraction() called with NULL arg" );
+        return;
+    }
+    p_dialog = p_arg->p_dialog;
+
+
+    /** \bug We store the interface object for the dialog in the p_private
+     * field of the core dialog object. This is not safe if we change
+     * interface while a dialog is loaded */
+
+    switch( p_dialog->i_action )
+    {
+    case INTERACT_NEW:
+        p_wxdialog = new InteractionDialog( p_intf, this, p_dialog );
+        p_dialog->p_private = (void*)p_wxdialog;
+        p_wxdialog->Show();
+        break;
+    case INTERACT_UPDATE:
+        p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
+        p_wxdialog->Update();
+        break;
+    case INTERACT_HIDE:
+        p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
+        p_wxdialog->Hide();
+        break;
+    }
+}
diff --git a/modules/gui/wxwidgets/dialogs/interaction.cpp b/modules/gui/wxwidgets/dialogs/interaction.cpp
new file mode 100644 (file)
index 0000000..b2c4e15
--- /dev/null
@@ -0,0 +1,178 @@
+/*****************************************************************************
+ * 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 $
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include "dialogs/interaction.hpp"
+
+#include <wx/statline.h>
+
+/*****************************************************************************
+ * Event Table.
+ *****************************************************************************/
+
+/* IDs for the controls and the menu commands */
+enum
+{
+     OkYes_Event,
+     No_Event,
+     Cancel_Event
+};
+
+BEGIN_EVENT_TABLE( InteractionDialog, wxFrame)
+    EVT_CLOSE( InteractionDialog::OnClose )
+    EVT_BUTTON( OkYes_Event, InteractionDialog::OnOkYes )
+    EVT_BUTTON( Cancel_Event, InteractionDialog::OnCancel)
+    EVT_BUTTON( No_Event, InteractionDialog::OnNo )
+END_EVENT_TABLE()
+
+/*****************************************************************************
+ * Constructor.
+ *****************************************************************************/
+InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
+                                      wxWindow *p_parent,
+                                      interaction_dialog_t *_p_dialog )
+  : wxFrame( p_parent, -1, wxU( _p_dialog->psz_title ) )
+{
+    /* Initializations */
+    p_intf = _p_intf;
+    p_dialog = _p_dialog;
+    SetIcon( *p_intf->p_sys->p_icon );
+
+    widgets_panel = new wxPanel( this, -1 );
+    widgets_sizer = new wxBoxSizer( wxVERTICAL );
+    widgets_panel->SetSizer( widgets_sizer );
+
+    buttons_panel = new wxPanel( this, -1 );
+    buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
+    buttons_panel->SetSizer( buttons_sizer );
+
+    main_sizer = new wxBoxSizer( wxVERTICAL );
+    main_sizer->Add( widgets_panel, 0, wxEXPAND | wxALL, 5 );
+    main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND  );
+    main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
+    SetSizer( main_sizer );
+
+    Render();
+}
+
+InteractionDialog::~InteractionDialog()
+{
+}
+
+void InteractionDialog::Update( )
+{
+    widgets_panel->DestroyChildren();
+    buttons_panel->DestroyChildren();
+    input_widgets.clear();
+    Render();
+    Show();
+}
+
+/// \todo Dirty - Clean that up
+void InteractionDialog::Render()
+{
+    wxStaticText *label;
+    wxTextCtrl *input;
+
+    //-------------- 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 );
+            widgets_sizer->Add( input );
+
+            InputWidget widget;
+            widget.control = input;
+            widget.val = &p_widget->val;
+            input_widgets.push_back( widget );
+        }
+    }
+    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 );
+    }
+
+}
+
+/*****************************************************************************
+ * Private methods.
+ *****************************************************************************/
+void InteractionDialog::OnClose( wxCloseEvent& event )
+{
+    Finish( DIALOG_CANCELLED );
+}
+
+void InteractionDialog::OnCancel( wxCommandEvent& event )
+{
+    Finish( DIALOG_CANCELLED );
+}
+
+void InteractionDialog::OnNo( wxCommandEvent& event )
+{
+    Finish( DIALOG_NO );
+}
+
+void InteractionDialog::OnOkYes( wxCommandEvent& event )
+{
+    Finish( DIALOG_OK_YES );
+}
+
+void InteractionDialog::Finish( int i_ret )
+{
+    vector<InputWidget>::iterator it = input_widgets.begin();
+    while ( it < input_widgets.end() )
+    {
+        (*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 );
+}
diff --git a/modules/gui/wxwidgets/dialogs/interaction.hpp b/modules/gui/wxwidgets/dialogs/interaction.hpp
new file mode 100644 (file)
index 0000000..23dbd6f
--- /dev/null
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * interaction.hpp : Headers for an interaction dialog
+ *****************************************************************************
+ * Copyright (C) 1999-2005 the VideoLAN team
+ * $Id: bookmarks.hpp 13444 2005-11-28 23:33:48Z dionoea $
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef _WXVLC_INTERACTION_H_
+#define _WXVLC_INTERACTION_H_
+
+#include "wxwidgets.hpp"
+#include <vlc_interaction.h>
+
+#include <vector>
+using namespace std;
+
+namespace wxvlc
+{
+
+    struct InputWidget
+    {
+        /// \todo Clean up
+        wxTextCtrl *control;
+        vlc_value_t *val;
+    };
+
+    class InteractionDialog: public wxFrame
+    {
+    public:
+        /* Constructor */
+        InteractionDialog( intf_thread_t *p_intf, wxWindow *p_parent,
+                           interaction_dialog_t * );
+        virtual ~InteractionDialog();
+
+        void Update();
+
+    private:
+        /* Event handlers (these functions should _not_ be virtual) */
+        void OnClose ( wxCloseEvent& event );
+        void OnOkYes ( wxCommandEvent& event );
+        void OnCancel( wxCommandEvent& event );
+        void OnNo    ( wxCommandEvent& event );
+
+        void Render();
+        void Finish( int );
+
+        wxBoxSizer *widgets_sizer;
+        wxPanel    *widgets_panel;
+        wxBoxSizer *buttons_sizer;
+        wxPanel    *buttons_panel;
+
+        wxBoxSizer *main_sizer;
+
+        DECLARE_EVENT_TABLE();
+
+        vector<InputWidget> input_widgets;
+
+        intf_thread_t *p_intf;
+        interaction_dialog_t *p_dialog;
+        wxWindow *p_parent;
+    };
+};
+
+#endif
index e553a9b64f9d84f812faa5564c7c509c5a98879b..f8a93542e5331fab593a27293af000586c33be07 100644 (file)
@@ -874,7 +874,7 @@ void Playlist::DeleteTreeItem( wxTreeItemId item )
 
 void Playlist::DeleteItem( int item_id )
 {
-    playlist_LockDelete( p_playlist, item_id );
+    playlist_Delete( p_playlist, item_id );
 }
 
 void Playlist::DeleteNode( playlist_item_t *p_item )
index 641258977575e84142b409bdf4e2462550d93321..0a0d8d9dc918dc49107728a56376568e845a7ebf 100644 (file)
@@ -471,8 +471,6 @@ Interface::Interface( intf_thread_t *_p_intf, long style ):
 
     SetIntfMinSize();
 
-    fprintf( stderr, "Adding callback to object %i\n", p_intf->i_object_id );
-
     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "interaction", InteractCallback, this );
     p_intf->b_interaction = VLC_TRUE;
@@ -1203,13 +1201,13 @@ void Interface::OnInteraction( wxCommandEvent& event )
 {
     interaction_dialog_t *p_dialog = (interaction_dialog_t *)
                                         event.GetClientData();
-    if( p_dialog->i_widgets == 0 ) return;
 
-    /// \todo : Code this . This is only test code. No locking, ...
-    wxString message = wxU( p_dialog->pp_widgets[0]->psz_text );
-    REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, 0 );
-    wxMessageBox( message, wxU( p_dialog->psz_title ) );
-    p_dialog->i_status = ANSWERED_DIALOG;
+    intf_dialog_args_t *p_arg = new intf_dialog_args_t;
+    p_arg->p_dialog = p_dialog;
+    p_arg->p_intf = p_intf;
+
+    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_INTERACTION,
+                                   0, p_arg );
 }
 
 static int InteractCallback( vlc_object_t *p_this,
@@ -1223,7 +1221,7 @@ static int InteractCallback( vlc_object_t *p_this,
     if( p_dialog->i_action == INTERACT_HIDE )
     {
         p_dialog->i_status = HIDDEN_DIALOG;
-        return;
+        return 0;
     }
 
     wxCommandEvent event( wxEVT_INTERACTION, -1 );