]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/interaction.cpp
A bit of headers cleanup
[vlc] / modules / gui / wxwidgets / dialogs / interaction.cpp
1 /*****************************************************************************
2  * interaction.cpp: wxWidgets handling of interaction dialogs
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "dialogs/interaction.hpp"
28
29 #include <wx/statline.h>
30
31 /*****************************************************************************
32  * Event Table.
33  *****************************************************************************/
34
35 /* IDs for the controls and the menu commands */
36 enum
37 {
38      No_Event,
39      NoShow_Event
40 };
41
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 )
51 END_EVENT_TABLE()
52
53 /*****************************************************************************
54  * Constructor.
55  *****************************************************************************/
56 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
57                                       wxWindow *p_parent,
58                                       interaction_dialog_t *_p_dialog )
59   : wxDialog( p_parent, -1, wxU( _p_dialog->psz_title ) )
60 {
61 #if 0
62     /* Initializations */
63     p_intf = _p_intf;
64     p_dialog = _p_dialog;
65     SetIcon( *p_intf->p_sys->p_icon );
66
67     widgets_panel = new wxPanel( this, -1 );
68     widgets_sizer = new wxBoxSizer( wxVERTICAL );
69     widgets_panel->SetSizer( widgets_sizer );
70
71     buttons_panel = new wxPanel( this, -1 );
72     buttons_sizer = new wxStdDialogButtonSizer;
73     buttons_panel->SetSizer( buttons_sizer );
74
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 );
80
81     b_noshow = false;
82     Render();
83 #endif
84 }
85
86 InteractionDialog::~InteractionDialog()
87 {
88 }
89
90 void InteractionDialog::Update( )
91 {
92 #if 0
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();
98     Render();
99     if( b_noshow == false )
100     {
101         Show();
102     }
103 #endif
104 }
105
106 /// \todo Dirty - Clean that up
107 void InteractionDialog::Render()
108 {
109 #if 0
110     wxStaticText *label;
111     wxTextCtrl   *input;
112     wxGauge      *gauge;
113
114
115     if( p_dialog->i_flags == DIALOG_BLOCKING_ERROR || p_dialog->i_flags == DIALOG_NONBLOCKING_ERROR )
116     {
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++ )
125         {
126             (*errors) << wxL2U( p_dialog->pp_widgets[i]->psz_text ) <<
127                            wxU( "\n" ) ;
128         }
129         widgets_sizer->Add( label );
130         widgets_sizer->Add( errors, 0, wxEXPAND|wxALL, 3 );
131     }
132     else
133     {
134         //-------------- Widgets ------------------
135         for( int i = 0 ; i< p_dialog->i_widgets; i++ )
136         {
137             user_widget_t* p_widget = p_dialog->pp_widgets[i];
138             /// \todo Merge cleanly with preferences widgets
139             switch( p_widget->i_type )
140             {
141             case WIDGET_TEXT:
142                 label = new wxStaticText( widgets_panel, -1,
143                                            wxU( p_widget->psz_text ) );
144                 widgets_sizer->Add( label );
145                 break;
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 );
152
153                 InputWidget widget;
154                 widget.control = input;
155                 widget.val = &p_widget->val;
156                 widget.i_type = WIDGET_INPUT_TEXT;
157                 input_widgets.push_back( widget );
158                 break;
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 ) );
167             }
168         }
169     }
170
171     //-------------- Buttons ------------------
172     if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
173     {
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 );
183     }
184     else if( p_dialog->i_flags & DIALOG_CLEAR_NOSHOW )
185     {
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") ) );
193         close->SetDefault();
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 );
201     }
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 );
208 #endif
209 }
210
211 /*****************************************************************************
212  * Private methods.
213  *****************************************************************************/
214 void InteractionDialog::OnClose( wxCloseEvent& event )
215 {
216     Finish( DIALOG_CANCELLED );
217 }
218
219 void InteractionDialog::OnCancel( wxCommandEvent& event )
220 {
221     Finish( DIALOG_CANCELLED );
222 }
223
224 void InteractionDialog::OnNo( wxCommandEvent& event )
225 {
226     Finish( DIALOG_NO );
227 }
228
229 void InteractionDialog::OnOkYes( wxCommandEvent& event )
230 {
231     Finish( DIALOG_OK_YES );
232 }
233
234 void InteractionDialog::OnClear( wxCommandEvent& event )
235 {
236 #if 0
237     int i;
238     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
239     for( i = p_dialog->i_widgets - 1 ; i >= 0 ; i-- )
240     {
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 );
245         free( p_widget );
246     }
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 );
254     Render();
255 #endif
256 }
257
258 void InteractionDialog::OnNoShow( wxCommandEvent& event )
259 {
260      b_noshow = event.IsChecked();
261 }
262
263 void InteractionDialog::Finish( int i_ret )
264 {
265 #if 0
266     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
267     vector<InputWidget>::iterator it = input_widgets.begin();
268     while ( it < input_widgets.end() )
269     {
270         if( (*it).i_type == WIDGET_INPUT_TEXT )
271             (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str(wxConvUTF8));
272         it++;
273     }
274     Hide();
275     p_dialog->i_status = ANSWERED_DIALOG;
276     p_dialog->i_return = i_ret;
277     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
278 #endif
279 }