Commit 29c81fbc authored by Clément Stenac's avatar Clément Stenac

Replace function callback by variable callback.

parent 27cd819c
......@@ -60,6 +60,8 @@ struct interaction_dialog_t
void * p_private; //< Private interface data
int i_status; //< Dialog status;
int i_action; //< Action to perform;
};
/**
......
......@@ -66,7 +66,7 @@ struct intf_thread_t
intf_dialog_args_t * );
/** Interaction stuff */
int ( *pf_interact ) ( intf_thread_t *, interaction_dialog_t *, int );
vlc_bool_t b_interaction;
/** Video window callbacks */
void * ( *pf_request_window ) ( intf_thread_t *, vout_thread_t *,
......
......@@ -36,6 +36,8 @@
#include <vlc/aout.h>
#include "charset.h"
#include <vlc_interaction.h>
#include <wx/splitter.h>
/* include the toolbar graphics */
......@@ -65,7 +67,8 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int DoInteract( intf_thread_t *, interaction_dialog_t *, int );
static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
vlc_value_t, void *);
/*****************************************************************************
* Local class declarations.
......@@ -296,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)
......@@ -343,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()
/*****************************************************************************
......@@ -358,7 +365,6 @@ Interface::Interface( intf_thread_t *_p_intf, long style ):
extra_frame = 0;
playlist_manager = 0;
p_intf->pf_interact = DoInteract;
/* Give our interface a nice little icon */
SetIcon( wxIcon( vlc_xpm ) );
......@@ -465,6 +471,12 @@ 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;
/* Show embedded playlist if requested */
if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
}
......@@ -487,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;
}
......@@ -1183,9 +1199,36 @@ void Interface::TogglePlayButton( int i_playing_status )
GetToolBar()->ToggleTool( PlayStream_Event, false );
}
static int DoInteract( intf_thread_t *, interaction_dialog_t *, int )
void Interface::OnInteraction( wxCommandEvent& event )
{
fprintf( stderr, "Doing interaction \n" );
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;
}
......
......@@ -142,6 +142,8 @@ namespace wxvlc
void OnSlowStream( wxCommandEvent& event );
void OnFastStream( wxCommandEvent& event );
void OnInteraction( wxCommandEvent& event );
void OnMenuOpen( wxMenuEvent& event );
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
......
......@@ -2096,6 +2096,7 @@ static int InputSourceInit( input_thread_t *p_input,
{
msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
intf_UserFatal( VLC_OBJECT( p_input), DIALOG_NOACCESS,
"Error opening stream",
"Unable to open '%s'", psz_mrl );
goto error;
}
......
......@@ -99,6 +99,7 @@ void intf_InteractionDestroy( interaction_t *p_interaction )
*/
void intf_InteractionManage( playlist_t *p_playlist )
{
vlc_value_t val;
int i_index;
interaction_t *p_interaction;
......@@ -134,13 +135,15 @@ void intf_InteractionManage( playlist_t *p_playlist )
// Ask interface to hide it
msg_Dbg( p_interaction, "Hiding dialog %i", p_dialog->i_id );
p_interaction->p_intf->pf_interact( p_interaction->p_intf,
p_dialog, INTERACT_HIDE );
p_dialog->i_action = INTERACT_HIDE;
val.p_address = p_dialog;
var_Set( p_interaction->p_intf, "interaction", val );
p_dialog->i_status = HIDING_DIALOG;
break;
case UPDATED_DIALOG:
p_interaction->p_intf->pf_interact( p_interaction->p_intf,
p_dialog, INTERACT_UPDATE );
p_dialog->i_action = INTERACT_UPDATE;
val.p_address = p_dialog;
var_Set( p_interaction->p_intf, "interaction", val );
p_dialog->i_status = SENT_DIALOG;
msg_Dbg( p_interaction, "Updating dialog %i, %i widgets",
p_dialog->i_id, p_dialog->i_widgets );
......@@ -153,10 +156,11 @@ void intf_InteractionManage( playlist_t *p_playlist )
break;
case NEW_DIALOG:
// This is truly a new dialog, send it.
p_interaction->p_intf->pf_interact( p_interaction->p_intf,
p_dialog, INTERACT_NEW );
msg_Dbg( p_interaction, "Creating dialog %i, %i widgets",
p_dialog->i_id, p_dialog->i_widgets );
p_dialog->i_action = INTERACT_NEW;
val.p_address = p_dialog;
var_Set( p_interaction->p_intf, "interaction", val );
msg_Dbg( p_interaction, "Creating dialog %i to interface %i, %i widgets",
p_dialog->i_id, p_interaction->p_intf->i_object_id, p_dialog->i_widgets );
p_dialog->i_status = SENT_DIALOG;
break;
}
......@@ -321,7 +325,7 @@ static void intf_InteractionSearchInterface( interaction_t *p_interaction )
{
intf_thread_t *p_intf = (intf_thread_t *)
p_list->p_values[i_index].p_object;
if( p_intf->pf_interact != NULL )
if( p_intf->b_interaction )
{
p_interaction->p_intf = p_intf;
break;
......
......@@ -98,8 +98,8 @@ intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module )
p_intf->pf_request_window = NULL;
p_intf->pf_release_window = NULL;
p_intf->pf_control_window = NULL;
p_intf->pf_interact = NULL;
p_intf->b_play = VLC_FALSE;
p_intf->b_interaction = VLC_FALSE;
/* Choose the best module */
p_intf->p_module = module_Need( p_intf, "interface", psz_module, 0 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment