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., 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_NO, InteractionDialog::OnNo )
50 EVT_BUTTON( wxID_CLEAR, InteractionDialog::OnClear )
51 EVT_CHECKBOX( NoShow_Event, InteractionDialog::OnNoShow )
54 /*****************************************************************************
56 *****************************************************************************/
57 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
59 interaction_dialog_t *_p_dialog )
60 : 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 wxBoxSizer( wxHORIZONTAL );
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 );
85 InteractionDialog::~InteractionDialog()
89 void InteractionDialog::Update( )
91 widgets_panel->DestroyChildren();
92 /* FIXME: Needed for the spacer */
93 buttons_sizer->Remove( 1 );buttons_sizer->Remove( 2 );buttons_sizer->Remove( 3 );
94 buttons_panel->DestroyChildren();
95 input_widgets.clear();
97 if( b_noshow == false )
103 /// \todo Dirty - Clean that up
104 void InteractionDialog::Render()
111 if( p_dialog->i_id == DIALOG_ERRORS )
113 wxTextCtrl *errors ; // Special case
114 label = new wxStaticText( widgets_panel, -1,
115 wxU( _("The following errors happened. More details might be "
116 "available in the Messages window.") ) );
117 errors = new wxTextCtrl( widgets_panel, -1, wxT(""),
118 wxDefaultPosition, wxDefaultSize,
119 wxTE_MULTILINE | wxTE_READONLY );
120 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
122 (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
125 widgets_sizer->Add( label );
126 widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
130 //-------------- Widgets ------------------
131 for( int i = 0 ; i< p_dialog->i_widgets; i++ )
133 user_widget_t* p_widget = p_dialog->pp_widgets[i];
134 /// \todo Merge cleanly with preferences widgets
135 switch( p_widget->i_type )
138 label = new wxStaticText( widgets_panel, -1,
139 wxU( p_widget->psz_text ) );
140 widgets_sizer->Add( label );
142 case WIDGET_INPUT_TEXT:
143 label = new wxStaticText( widgets_panel, -1,
144 wxU( p_widget->psz_text ) );
145 input = new wxTextCtrl( widgets_panel, -1 );
146 widgets_sizer->Add( label , 0, 0, 0);
147 widgets_sizer->Add( input, 0, wxEXPAND , 0 );
150 widget.control = input;
151 widget.val = &p_widget->val;
152 widget.i_type = WIDGET_INPUT_TEXT;
153 input_widgets.push_back( widget );
155 case WIDGET_PROGRESS:
156 label = new wxStaticText(widgets_panel, -1,
157 wxU( p_widget->psz_text ) );
158 gauge = new wxGauge( widgets_panel, -1, 100,
159 wxDefaultPosition, wxDefaultSize );
160 widgets_sizer->Add( label , 0, 0, 0);
161 widgets_sizer->Add( gauge, 0, wxEXPAND , 0 );
162 gauge->SetValue( (int)(p_widget->val.f_float ) );
167 //-------------- Buttons ------------------
168 if( p_dialog->i_flags & DIALOG_OK_CANCEL )
170 wxButton *ok = new wxButton( buttons_panel,
171 wxID_OK, wxU( _("OK") ) );
172 wxButton *cancel = new wxButton( buttons_panel,
173 wxID_CANCEL, wxU( _("Cancel") ) );
174 buttons_sizer->Add( ok, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
175 buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_CENTER, 5 );
177 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
179 wxButton *yes = new wxButton( buttons_panel,
180 wxID_YES, wxU( _("Yes") ) );
181 wxButton *no = new wxButton( buttons_panel,
182 wxID_NO, wxU( _("No") ) );
183 wxButton *cancel = new wxButton( buttons_panel,
184 wxID_CANCEL, wxU( _("Cancel") ) );
185 buttons_sizer->Add( yes, 0, wxEXPAND | wxRIGHT| wxLEFT |
187 buttons_sizer->Add( no, 0, wxEXPAND | wxRIGHT| wxLEFT |
189 buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT |
192 else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
194 wxCheckBox *noshow = new wxCheckBox( buttons_panel,
195 NoShow_Event, wxU( _("Don't show") ) );
196 noshow->SetValue( b_noshow );
197 wxButton *clear = new wxButton( buttons_panel,
198 wxID_CLEAR, wxU( _("Clear") ) );
199 buttons_sizer->Add( noshow, 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_LEFT, 5 );
200 buttons_sizer->Add( 0, 0, 1 );
201 buttons_sizer->Add( clear , 0, wxEXPAND | wxRIGHT| wxLEFT | wxALIGN_RIGHT, 5 );
204 widgets_sizer->Layout();
205 widgets_panel->SetSizerAndFit( widgets_sizer );
206 buttons_sizer->Layout();
207 buttons_panel->SetSizerAndFit( buttons_sizer );
208 main_sizer->Layout();
209 SetSizerAndFit( main_sizer );
212 /*****************************************************************************
214 *****************************************************************************/
215 void InteractionDialog::OnClose( wxCloseEvent& event )
217 Finish( DIALOG_CANCELLED );
220 void InteractionDialog::OnCancel( wxCommandEvent& event )
222 Finish( DIALOG_CANCELLED );
225 void InteractionDialog::OnNo( wxCommandEvent& event )
230 void InteractionDialog::OnOkYes( wxCommandEvent& event )
232 Finish( DIALOG_OK_YES );
235 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 FREE( p_widget->psz_text );
243 FREE( 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 );
257 void InteractionDialog::OnNoShow( wxCommandEvent& event )
259 b_noshow = event.IsChecked();
262 void InteractionDialog::Finish( int i_ret )
264 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
265 vector<InputWidget>::iterator it = input_widgets.begin();
266 while ( it < input_widgets.end() )
268 if( (*it).i_type == WIDGET_INPUT_TEXT )
269 (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str());
273 p_dialog->i_status = ANSWERED_DIALOG;
274 p_dialog->i_return = i_ret;
275 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );