1 /*****************************************************************************
2 * interaction.cpp: wxWidgets handling of interaction dialogs
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
5 * $Id: bookmarks.cpp 13106 2005-11-02 19:20:34Z zorglub $
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include "dialogs/interaction.hpp"
29 #include <wx/statline.h>
31 /*****************************************************************************
33 *****************************************************************************/
35 /* IDs for the controls and the menu commands */
43 BEGIN_EVENT_TABLE( InteractionDialog, wxFrame)
44 EVT_CLOSE( InteractionDialog::OnClose )
45 EVT_BUTTON( OkYes_Event, InteractionDialog::OnOkYes )
46 EVT_BUTTON( Cancel_Event, InteractionDialog::OnCancel)
47 EVT_BUTTON( No_Event, InteractionDialog::OnNo )
50 /*****************************************************************************
52 *****************************************************************************/
53 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
55 interaction_dialog_t *_p_dialog )
56 : wxFrame( p_parent, -1, wxU( _p_dialog->psz_title ) )
61 SetIcon( *p_intf->p_sys->p_icon );
63 widgets_panel = new wxPanel( this, -1 );
64 widgets_sizer = new wxBoxSizer( wxVERTICAL );
65 widgets_panel->SetSizer( widgets_sizer );
67 buttons_panel = new wxPanel( this, -1 );
68 buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
69 buttons_panel->SetSizer( buttons_sizer );
71 main_sizer = new wxBoxSizer( wxVERTICAL );
72 main_sizer->Add( widgets_panel, 0, wxEXPAND | wxALL, 5 );
73 main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND );
74 main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
75 SetSizer( main_sizer );
80 InteractionDialog::~InteractionDialog()
84 void InteractionDialog::Update( )
86 widgets_panel->DestroyChildren();
87 buttons_panel->DestroyChildren();
88 input_widgets.clear();
93 /// \todo Dirty - Clean that up
94 void InteractionDialog::Render()
99 //-------------- Widgets ------------------
100 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
102 user_widget_t* p_widget = p_dialog->pp_widgets[i];
103 /// \todo Merge cleanly with preferences widgets
104 switch( p_widget->i_type )
107 label = new wxStaticText( widgets_panel, -1,
108 wxU( p_widget->psz_text ) );
109 widgets_sizer->Add( label );
111 case WIDGET_INPUT_TEXT:
112 label = new wxStaticText( widgets_panel, -1,
113 wxU( p_widget->psz_text ) );
114 input = new wxTextCtrl( widgets_panel, -1 );
115 widgets_sizer->Add( label );
116 widgets_sizer->Add( input );
119 widget.control = input;
120 widget.val = &p_widget->val;
121 input_widgets.push_back( widget );
124 widgets_sizer->Layout();
125 widgets_panel->SetSizerAndFit( widgets_sizer );
126 main_sizer->Layout();
127 SetSizerAndFit( main_sizer );
129 //-------------- Buttons ------------------
130 if( p_dialog->i_flags & DIALOG_OK_CANCEL )
132 wxButton *ok = new wxButton( buttons_panel,
133 OkYes_Event, wxU( _("OK") ) );
134 wxButton *cancel = new wxButton( buttons_panel,
135 Cancel_Event, wxU( _("Cancel") ) );
136 buttons_sizer->Add( ok, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
137 buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
142 /*****************************************************************************
144 *****************************************************************************/
145 void InteractionDialog::OnClose( wxCloseEvent& event )
147 Finish( DIALOG_CANCELLED );
150 void InteractionDialog::OnCancel( wxCommandEvent& event )
152 Finish( DIALOG_CANCELLED );
155 void InteractionDialog::OnNo( wxCommandEvent& event )
160 void InteractionDialog::OnOkYes( wxCommandEvent& event )
162 Finish( DIALOG_OK_YES );
165 void InteractionDialog::Finish( int i_ret )
167 vector<InputWidget>::iterator it = input_widgets.begin();
168 while ( it < input_widgets.end() )
170 (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str() );
174 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
175 p_dialog->i_status = ANSWERED_DIALOG;
176 p_dialog->i_return = i_ret;
177 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );