]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/interface.cpp
Replace function callback by variable callback.
[vlc] / modules / gui / wxwidgets / interface.cpp
index adc9fd8ce0ae8fb3a6fd40cced05ae208647db10..641258977575e84142b409bdf4e2462550d93321 100644 (file)
@@ -36,6 +36,8 @@
 #include <vlc/aout.h>
 #include "charset.h"
 
+#include <vlc_interaction.h>
+
 #include <wx/splitter.h>
 
 /* include the toolbar graphics */
 #include "../../../share/vlc16x16.xpm"
 #endif
 
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
+                             vlc_value_t, void *);
+
 /*****************************************************************************
  * Local class declarations.
  *****************************************************************************/
@@ -117,19 +125,38 @@ class Splitter : public wxSplitterWindow
 public:
     Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
       : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
+#if defined( __WXMSW__ )
+                          wxCLIP_CHILDREN ),
+#else
                           wxCLIP_CHILDREN | wxSP_3DSASH ),
-        p_intf(_p_intf), i_sash_position(150), i_width(-1)
+#endif
+        p_intf(_p_intf), b_video(0), i_delay(0)
     {
         SetSashSize( 0 );
+
+        wxSize size = wxSize(-1, 150);
+        wxPoint p = wxPoint(0,0);
+        bool b_dummy;
+        WindowSettings *ws = p_intf->p_sys->p_window_settings;
+        ws->GetSettings( WindowSettings::ID_SMALL_PLAYLIST, b_dummy, p, size );
+
+        i_width = size.GetWidth();
+        i_sash_position = size.GetHeight();
+        b_show_on_start = !!p.x;
     }
 
-    virtual ~Splitter() {};
+    virtual ~Splitter()
+    {
+        WindowSettings *ws = p_intf->p_sys->p_window_settings;
+        ws->SetSettings( WindowSettings::ID_SMALL_PLAYLIST, true,
+                         wxPoint(!!GetWindow2(),0),
+                         wxSize(i_width, i_sash_position) );
+    };
 
     virtual bool Split( wxWindow* window1, wxWindow* window2 )
     {
-        SetSashSize( -1 );
-
-        wxSize size = wxSize( i_width, i_sash_position - GetSashSize() );
+        SetSashSize( 0 );
+        wxSize size = wxSize( i_width, i_sash_position );
         if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
 
         return wxSplitterWindow::SplitHorizontally( window1, window2,
@@ -142,6 +169,8 @@ public:
         return wxSplitterWindow::Unsplit( window );
     }
 
+    bool ShowOnStart() { return b_show_on_start; }
+
 private:
     DECLARE_EVENT_TABLE()
 
@@ -152,22 +181,41 @@ private:
             p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
             p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
         {
+            if( !b_video ) i_delay = mdate() + 1000000;
+            b_video = VLC_TRUE;
+
+            SetSashSize( -1 );
+
+#if defined( __WXMSW__ )
             SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
+#else
+            SetSashPosition( event.GetSize().GetHeight() -
+                             i_sash_position - GetSashSize() );
+#endif
         }
         else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
         {
             wxSize size = GetWindow1()->GetSizer()->GetMinSize();
 
+            if( b_video ) i_delay = mdate() + 1000000;
+            b_video = VLC_FALSE;
+
             if( event.GetSize().GetHeight() - size.GetHeight() )
             {
+                SetSashSize( 0 );
+
                 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
-                i_sash_position = event.GetSize().GetHeight() -
-                    size.GetHeight();
-                i_width = event.GetSize().GetWidth();
 
-                size = wxSize( i_width, i_sash_position - GetSashSize() );
-                if( GetWindow2()->GetSizer() )
-                    GetWindow2()->GetSizer()->SetMinSize( size );
+                if( i_delay < mdate() )
+                {
+                    i_sash_position = event.GetSize().GetHeight() -
+                        size.GetHeight();
+                    i_width = event.GetSize().GetWidth();
+
+                    size = wxSize( i_width, i_sash_position );
+                    if( GetWindow2()->GetSizer() )
+                        GetWindow2()->GetSizer()->SetMinSize( size );
+                }
             }
         }
 
@@ -177,13 +225,24 @@ private:
     void OnSashPosChanged( wxSplitterEvent &event )
     {
         if( !GetSize().GetHeight() ){ event.Skip(); return; }
-        i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
+
+        if( i_delay < mdate() )
+        {
+            i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
+
+            wxSize size = wxSize( i_width, i_sash_position );
+            if( GetWindow2()->GetSizer() )
+                GetWindow2()->GetSizer()->SetMinSize( size );
+        }
         event.Skip();
     }
 
     intf_thread_t *p_intf;
     int i_sash_position;
     int i_width;
+    vlc_bool_t b_video;
+    mtime_t i_delay;
+    vlc_bool_t b_show_on_start;
 };
 
 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
@@ -240,9 +299,11 @@ enum
     UpdateVLC_Event,
     VLM_Event,
 
-    Iconize_Event
+    Iconize_Event,
 };
 
+DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTERACTION );
+
 BEGIN_EVENT_TABLE(Interface, wxFrame)
     /* Menu events */
     EVT_MENU(Exit_Event, Interface::OnExit)
@@ -287,6 +348,8 @@ BEGIN_EVENT_TABLE(Interface, wxFrame)
     /* Custom events */
     EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
     EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
+
+    EVT_COMMAND( -1, wxEVT_INTERACTION, Interface::OnInteraction )
 END_EVENT_TABLE()
 
 /*****************************************************************************
@@ -302,6 +365,7 @@ Interface::Interface( intf_thread_t *_p_intf, long style ):
     extra_frame = 0;
     playlist_manager = 0;
 
+
     /* Give our interface a nice little icon */
     SetIcon( wxIcon( vlc_xpm ) );
 
@@ -406,6 +470,15 @@ Interface::Interface( intf_thread_t *_p_intf, long style ):
     if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
 
     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;
+
+    /* Show embedded playlist if requested */
+    if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
 }
 
 Interface::~Interface()
@@ -426,8 +499,12 @@ Interface::~Interface()
     if( p_systray ) delete p_systray;
 #endif
 
+    p_intf->b_interaction = VLC_FALSE;
+    var_DelCallback( p_intf, "interaction", InteractCallback, this );
+
     if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
 
+
     /* Clean up */
     delete timer;
 }
@@ -1122,6 +1199,39 @@ void Interface::TogglePlayButton( int i_playing_status )
     GetToolBar()->ToggleTool( PlayStream_Event, false );
 }
 
+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;
+}
+
+static int InteractCallback( vlc_object_t *p_this,
+                             const char *psz_var, vlc_value_t old_val,
+                             vlc_value_t new_val, void *param )
+{
+    Interface *p_interface = (Interface*)param;
+    interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);
+
+    /// Not handled
+    if( p_dialog->i_action == INTERACT_HIDE )
+    {
+        p_dialog->i_status = HIDDEN_DIALOG;
+        return;
+    }
+
+    wxCommandEvent event( wxEVT_INTERACTION, -1 );
+    event.SetClientData( new_val.p_address );
+    p_interface->AddPendingEvent( event );
+    return VLC_SUCCESS;
+}
+
 #if wxUSE_DRAG_AND_DROP
 /*****************************************************************************
  * Definition of DragAndDrop class.