1 /*****************************************************************************
2 * interaction.cpp: wxWidgets handling of interaction dialogs
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 */
42 BEGIN_EVENT_TABLE( InteractionDialog, wxDialog)
43 EVT_CLOSE( InteractionDialog::OnClose )
44 EVT_BUTTON( wxID_OK, InteractionDialog::OnOkYes )
45 EVT_BUTTON( wxID_YES, InteractionDialog::OnOkYes )
46 EVT_BUTTON( wxID_CANCEL, InteractionDialog::OnCancel)
47 EVT_BUTTON( wxID_CLOSE, InteractionDialog::OnCancel)
48 EVT_BUTTON( wxID_NO, InteractionDialog::OnNo )
49 EVT_BUTTON( wxID_CLEAR, InteractionDialog::OnClear )
50 EVT_CHECKBOX( NoShow_Event, InteractionDialog::OnNoShow )
53 /*****************************************************************************
55 *****************************************************************************/
56 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
58 interaction_dialog_t *_p_dialog )
59 : wxDialog( p_parent, -1, wxU( _p_dialog->psz_title ) )
65 SetIcon( *p_intf->p_sys->p_icon );
67 widgets_panel = new wxPanel( this, -1 );
68 widgets_sizer = new wxBoxSizer( wxVERTICAL );
69 widgets_panel->SetSizer( widgets_sizer );
71 buttons_panel = new wxPanel( this, -1 );
72 buttons_sizer = new wxStdDialogButtonSizer;
73 buttons_panel->SetSizer( buttons_sizer );
75 main_sizer = new wxBoxSizer( wxVERTICAL );
76 main_sizer->Add( widgets_panel, 1, wxEXPAND | wxALL, 5 );
77 main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND );
78 main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
79 SetSizer( main_sizer );
86 InteractionDialog::~InteractionDialog()
90 void InteractionDialog::Update( )
93 widgets_panel->DestroyChildren();
94 /* FIXME: Needed for the spacer */
95 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
96 buttons_panel->DestroyChildren();
97 input_widgets.clear();
99 if( b_noshow == false )
106 /// \todo Dirty - Clean that up
107 void InteractionDialog::Render()
115 if( p_dialog->i_flags == DIALOG_BLOCKING_ERROR || p_dialog->i_flags == DIALOG_NONBLOCKING_ERROR )
117 wxTextCtrl *errors ; // Special case
118 label = new wxStaticText( widgets_panel, -1,
119 wxU( _("The following errors occurred. More details might be "
120 "available in the Messages window.") ) );
121 errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
122 wxDefaultPosition, wxDefaultSize,
123 wxTE_MULTILINE | wxTE_READONLY );
124 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
126 (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
129 widgets_sizer->Add( label );
130 widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
134 //-------------- Widgets ------------------
135 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
137 user_widget_t* p_widget = p_dialog->pp_widgets[i];
138 /// \todo Merge cleanly with preferences widgets
139 switch( p_widget->i_type )
142 label = new wxStaticText( widgets_panel, -1,
143 wxU( p_widget->psz_text ) );
144 widgets_sizer->Add( label );
146 case WIDGET_INPUT_TEXT:
147 label = new wxStaticText( widgets_panel, -1,
148 wxU( p_widget->psz_text ) );
149 input = new wxTextCtrl( widgets_panel, -1 );
150 widgets_sizer->Add( label , 0, 0, 0);
151 widgets_sizer->Add( input, 0, wxEXPAND , 0 );
154 widget.control = input;
155 widget.val = &p_widget->val;
156 widget.i_type = WIDGET_INPUT_TEXT;
157 input_widgets.push_back( widget );
159 case WIDGET_PROGRESS:
160 label = new wxStaticText(widgets_panel, -1,
161 wxU( p_widget->psz_text ) );
162 gauge = new wxGauge( widgets_panel, -1, 100,
163 wxDefaultPosition, wxDefaultSize );
164 widgets_sizer->Add( label , 0, 0, 0);
165 widgets_sizer->Add( gauge, 0, wxEXPAND , 0 );
166 gauge->SetValue( (int)(p_widget->val.f_float ) );
171 //-------------- Buttons ------------------
172 if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
174 wxButton *yes = new wxButton( buttons_panel,
175 wxID_YES, wxU( _("&Yes") ) );
176 wxButton *no = new wxButton( buttons_panel,
177 wxID_NO, wxU( _("&No") ) );
178 wxButton *cancel = new wxButton( buttons_panel,
179 wxID_CANCEL, wxU( _("&Cancel") ) );
180 buttons_sizer->AddButton( yes );
181 buttons_sizer->AddButton( no );
182 buttons_sizer->AddButton( cancel );
184 else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
186 wxCheckBox *noshow = new wxCheckBox( buttons_panel,
187 NoShow_Event, wxU( _("Don't show further errors") ) );
188 noshow->SetValue( b_noshow );
189 wxButton *clear = new wxButton( buttons_panel,
190 wxID_CLEAR, wxU( _("&Clear") ) );
191 wxButton *close = new wxButton( buttons_panel, wxID_CLOSE,
192 wxU( _("&Close") ) );
194 buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT|
195 wxLEFT | wxALIGN_LEFT, 5 );
196 buttons_sizer->Add( 0, 0, 1 );
197 buttons_sizer->AddButton( clear );
198 buttons_sizer->SetNegativeButton( clear );
199 buttons_sizer->AddButton( close );
200 buttons_sizer->SetAffirmativeButton( close );
202 widgets_sizer->Layout();
203 widgets_panel->SetSizerAndFit( widgets_sizer );
204 buttons_sizer->Realize();
205 buttons_panel->SetSizerAndFit( buttons_sizer );
206 main_sizer->Layout();
207 SetSizerAndFit( main_sizer );
211 /*****************************************************************************
213 *****************************************************************************/
214 void InteractionDialog::OnClose( wxCloseEvent& event )
216 Finish( DIALOG_CANCELLED );
219 void InteractionDialog::OnCancel( wxCommandEvent& event )
221 Finish( DIALOG_CANCELLED );
224 void InteractionDialog::OnNo( wxCommandEvent& event )
229 void InteractionDialog::OnOkYes( wxCommandEvent& event )
231 Finish( DIALOG_OK_YES );
234 void InteractionDialog::OnClear( wxCommandEvent& event )
238 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
239 for( i = p_dialog->i_widgets - 1 ; i >= 0 ; i-- )
241 user_widget_t *p_widget = p_dialog->pp_widgets[i];
242 FREENULL( p_widget->psz_text );
243 FREENULL( p_widget->val.psz_string );
244 REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, i );
247 widgets_panel->DestroyChildren();
248 /* FIXME: Needed for the spacer */
249 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );
250 buttons_sizer->Remove( 3 );
251 buttons_panel->DestroyChildren();
252 input_widgets.clear();
253 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
258 void InteractionDialog::OnNoShow( wxCommandEvent& event )
260 b_noshow = event.IsChecked();
263 void InteractionDialog::Finish( int i_ret )
266 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
267 vector<InputWidget>::iterator it = input_widgets.begin();
268 while ( it < input_widgets.end() )
270 if( (*it).i_type == WIDGET_INPUT_TEXT )
271 (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str(wxConvUTF8));
275 p_dialog->i_status = ANSWERED_DIALOG;
276 p_dialog->i_return = i_ret;
277 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );