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 ) )
64 SetIcon( *p_intf->p_sys->p_icon );
66 widgets_panel = new wxPanel( this, -1 );
67 widgets_sizer = new wxBoxSizer( wxVERTICAL );
68 widgets_panel->SetSizer( widgets_sizer );
70 buttons_panel = new wxPanel( this, -1 );
71 buttons_sizer = new wxStdDialogButtonSizer;
72 buttons_panel->SetSizer( buttons_sizer );
74 main_sizer = new wxBoxSizer( wxVERTICAL );
75 main_sizer->Add( widgets_panel, 1, wxEXPAND | wxALL, 5 );
76 main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND );
77 main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
78 SetSizer( main_sizer );
84 InteractionDialog::~InteractionDialog()
88 void InteractionDialog::Update( )
90 widgets_panel->DestroyChildren();
91 /* FIXME: Needed for the spacer */
92 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
93 buttons_panel->DestroyChildren();
94 input_widgets.clear();
96 if( b_noshow == false )
102 /// \todo Dirty - Clean that up
103 void InteractionDialog::Render()
110 if( p_dialog->i_flags == DIALOG_BLOCKING_ERROR || p_dialog->i_flags == DIALOG_NONBLOCKING_ERROR )
112 wxTextCtrl *errors ; // Special case
113 label = new wxStaticText( widgets_panel, -1,
114 wxU( _("The following errors occurred. More details might be "
115 "available in the Messages window.") ) );
116 errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
117 wxDefaultPosition, wxDefaultSize,
118 wxTE_MULTILINE | wxTE_READONLY );
119 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
121 (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
124 widgets_sizer->Add( label );
125 widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
129 //-------------- Widgets ------------------
130 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
132 user_widget_t* p_widget = p_dialog->pp_widgets[i];
133 /// \todo Merge cleanly with preferences widgets
134 switch( p_widget->i_type )
137 label = new wxStaticText( widgets_panel, -1,
138 wxU( p_widget->psz_text ) );
139 widgets_sizer->Add( label );
141 case WIDGET_INPUT_TEXT:
142 label = new wxStaticText( widgets_panel, -1,
143 wxU( p_widget->psz_text ) );
144 input = new wxTextCtrl( widgets_panel, -1 );
145 widgets_sizer->Add( label , 0, 0, 0);
146 widgets_sizer->Add( input, 0, wxEXPAND , 0 );
149 widget.control = input;
150 widget.val = &p_widget->val;
151 widget.i_type = WIDGET_INPUT_TEXT;
152 input_widgets.push_back( widget );
154 case WIDGET_PROGRESS:
155 label = new wxStaticText(widgets_panel, -1,
156 wxU( p_widget->psz_text ) );
157 gauge = new wxGauge( widgets_panel, -1, 100,
158 wxDefaultPosition, wxDefaultSize );
159 widgets_sizer->Add( label , 0, 0, 0);
160 widgets_sizer->Add( gauge, 0, wxEXPAND , 0 );
161 gauge->SetValue( (int)(p_widget->val.f_float ) );
166 //-------------- Buttons ------------------
167 if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
169 wxButton *yes = new wxButton( buttons_panel,
170 wxID_YES, wxU( _("&Yes") ) );
171 wxButton *no = new wxButton( buttons_panel,
172 wxID_NO, wxU( _("&No") ) );
173 wxButton *cancel = new wxButton( buttons_panel,
174 wxID_CANCEL, wxU( _("&Cancel") ) );
175 buttons_sizer->AddButton( yes );
176 buttons_sizer->AddButton( no );
177 buttons_sizer->AddButton( cancel );
180 else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
182 wxCheckBox *noshow = new wxCheckBox( buttons_panel,
183 NoShow_Event, wxU( _("Don't show further errors") ) );
184 noshow->SetValue( b_noshow );
185 wxButton *clear = new wxButton( buttons_panel,
186 wxID_CLEAR, wxU( _("&Clear") ) );
187 wxButton *close = new wxButton( buttons_panel, wxID_CLOSE,
188 wxU( _("&Close") ) );
190 buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT|
191 wxLEFT | wxALIGN_LEFT, 5 );
192 buttons_sizer->Add( 0, 0, 1 );
193 buttons_sizer->AddButton( clear );
194 buttons_sizer->SetNegativeButton( clear );
195 buttons_sizer->AddButton( close );
196 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 FREENULL( p_widget->psz_text );
238 FREENULL( 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 );