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 #define FREE( i ) { if( i ) free( i ); i = NULL; }
33 /*****************************************************************************
35 *****************************************************************************/
37 /* IDs for the controls and the menu commands */
44 BEGIN_EVENT_TABLE( InteractionDialog, wxDialog)
45 EVT_CLOSE( InteractionDialog::OnClose )
46 EVT_BUTTON( wxID_OK, InteractionDialog::OnOkYes )
47 EVT_BUTTON( wxID_YES, InteractionDialog::OnOkYes )
48 EVT_BUTTON( wxID_CANCEL, InteractionDialog::OnCancel)
49 EVT_BUTTON( wxID_CLOSE, InteractionDialog::OnCancel)
50 EVT_BUTTON( wxID_NO, InteractionDialog::OnNo )
51 EVT_BUTTON( wxID_CLEAR, InteractionDialog::OnClear )
52 EVT_CHECKBOX( NoShow_Event, InteractionDialog::OnNoShow )
55 /*****************************************************************************
57 *****************************************************************************/
58 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
60 interaction_dialog_t *_p_dialog )
61 : wxDialog( p_parent, -1, wxU( _p_dialog->psz_title ) )
66 SetIcon( *p_intf->p_sys->p_icon );
68 widgets_panel = new wxPanel( this, -1 );
69 widgets_sizer = new wxBoxSizer( wxVERTICAL );
70 widgets_panel->SetSizer( widgets_sizer );
72 buttons_panel = new wxPanel( this, -1 );
73 buttons_sizer = new wxStdDialogButtonSizer;
74 buttons_panel->SetSizer( buttons_sizer );
76 main_sizer = new wxBoxSizer( wxVERTICAL );
77 main_sizer->Add( widgets_panel, 1, wxEXPAND | wxALL, 5 );
78 main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND );
79 main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
80 SetSizer( main_sizer );
86 InteractionDialog::~InteractionDialog()
90 void InteractionDialog::Update( )
92 widgets_panel->DestroyChildren();
93 /* FIXME: Needed for the spacer */
94 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
95 buttons_panel->DestroyChildren();
96 input_widgets.clear();
98 if( b_noshow == false )
104 /// \todo Dirty - Clean that up
105 void InteractionDialog::Render()
112 if( p_dialog->i_flags == DIALOG_BLOCKING_ERROR || p_dialog->i_flags == DIALOG_NONBLOCKING_ERROR )
114 wxTextCtrl *errors ; // Special case
115 label = new wxStaticText( widgets_panel, -1,
116 wxU( _("The following errors occurred. More details might be "
117 "available in the Messages window.") ) );
118 errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
119 wxDefaultPosition, wxDefaultSize,
120 wxTE_MULTILINE | wxTE_READONLY );
121 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
123 (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
126 widgets_sizer->Add( label );
127 widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
131 //-------------- Widgets ------------------
132 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
134 user_widget_t* p_widget = p_dialog->pp_widgets[i];
135 /// \todo Merge cleanly with preferences widgets
136 switch( p_widget->i_type )
139 label = new wxStaticText( widgets_panel, -1,
140 wxU( p_widget->psz_text ) );
141 widgets_sizer->Add( label );
143 case WIDGET_INPUT_TEXT:
144 label = new wxStaticText( widgets_panel, -1,
145 wxU( p_widget->psz_text ) );
146 input = new wxTextCtrl( widgets_panel, -1 );
147 widgets_sizer->Add( label , 0, 0, 0);
148 widgets_sizer->Add( input, 0, wxEXPAND , 0 );
151 widget.control = input;
152 widget.val = &p_widget->val;
153 widget.i_type = WIDGET_INPUT_TEXT;
154 input_widgets.push_back( widget );
156 case WIDGET_PROGRESS:
157 label = new wxStaticText(widgets_panel, -1,
158 wxU( p_widget->psz_text ) );
159 gauge = new wxGauge( widgets_panel, -1, 100,
160 wxDefaultPosition, wxDefaultSize );
161 widgets_sizer->Add( label , 0, 0, 0);
162 widgets_sizer->Add( gauge, 0, wxEXPAND , 0 );
163 gauge->SetValue( (int)(p_widget->val.f_float ) );
168 //-------------- Buttons ------------------
169 if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
171 wxButton *yes = new wxButton( buttons_panel,
172 wxID_YES, wxU( _("&Yes") ) );
173 wxButton *no = new wxButton( buttons_panel,
174 wxID_NO, wxU( _("&No") ) );
175 wxButton *cancel = new wxButton( buttons_panel,
176 wxID_CANCEL, wxU( _("&Cancel") ) );
177 buttons_sizer->AddButton( yes );
178 buttons_sizer->AddButton( no );
179 buttons_sizer->AddButton( cancel );
181 else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
183 wxCheckBox *noshow = new wxCheckBox( buttons_panel,
184 NoShow_Event, wxU( _("Don't show further errors") ) );
185 noshow->SetValue( b_noshow );
186 wxButton *clear = new wxButton( buttons_panel,
187 wxID_CLEAR, wxU( _("&Clear") ) );
188 wxButton *close = new wxButton( buttons_panel, wxID_CLOSE,
189 wxU( _("&Close") ) );
191 buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT|
192 wxLEFT | wxALIGN_LEFT, 5 );
193 buttons_sizer->Add( 0, 0, 1 );
194 buttons_sizer->AddButton( clear );
195 buttons_sizer->SetNegativeButton( clear );
196 buttons_sizer->AddButton( close );
197 buttons_sizer->SetAffirmativeButton( close );
199 widgets_sizer->Layout();
200 widgets_panel->SetSizerAndFit( widgets_sizer );
201 buttons_sizer->Realize();
202 buttons_panel->SetSizerAndFit( buttons_sizer );
203 main_sizer->Layout();
204 SetSizerAndFit( main_sizer );
207 /*****************************************************************************
209 *****************************************************************************/
210 void InteractionDialog::OnClose( wxCloseEvent& event )
212 Finish( DIALOG_CANCELLED );
215 void InteractionDialog::OnCancel( wxCommandEvent& event )
217 Finish( DIALOG_CANCELLED );
220 void InteractionDialog::OnNo( wxCommandEvent& event )
225 void InteractionDialog::OnOkYes( wxCommandEvent& event )
227 Finish( DIALOG_OK_YES );
230 void InteractionDialog::OnClear( wxCommandEvent& event )
233 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
234 for( i = p_dialog->i_widgets - 1 ; i >= 0 ; i-- )
236 user_widget_t *p_widget = p_dialog->pp_widgets[i];
237 FREE( p_widget->psz_text );
238 FREE( p_widget->val.psz_string );
239 REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, i );
242 widgets_panel->DestroyChildren();
243 /* FIXME: Needed for the spacer */
244 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );
245 buttons_sizer->Remove( 3 );
246 buttons_panel->DestroyChildren();
247 input_widgets.clear();
248 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
252 void InteractionDialog::OnNoShow( wxCommandEvent& event )
254 b_noshow = event.IsChecked();
257 void InteractionDialog::Finish( int i_ret )
259 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
260 vector<InputWidget>::iterator it = input_widgets.begin();
261 while ( it < input_widgets.end() )
263 if( (*it).i_type == WIDGET_INPUT_TEXT )
264 (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str());
268 p_dialog->i_status = ANSWERED_DIALOG;
269 p_dialog->i_return = i_ret;
270 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );