]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/subtitles.cpp
98b7d4a69a0da60fce1083393db5b6131c08d3e2
[vlc] / modules / gui / wxwidgets / dialogs / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include "dialogs/subtitles.hpp"
25 #include <wx/combobox.h>
26 #include <wx/statline.h>
27 #include <wx/spinctrl.h>
28
29 #ifndef wxRB_SINGLE
30 #   define wxRB_SINGLE 0
31 #endif
32
33 /*****************************************************************************
34  * Event Table.
35  *****************************************************************************/
36
37 /* IDs for the controls and the menu commands */
38 enum
39 {
40     FileBrowse_Event = wxID_HIGHEST,
41 };
42
43 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
44     /* Button events */
45     EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
46     EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
47     EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
48
49 END_EVENT_TABLE()
50
51 /*****************************************************************************
52  * Constructor.
53  *****************************************************************************/
54 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
55     wxDialog( _p_parent, -1, wxU(_("Subtitle options")),
56               wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
57 {
58     /* Initializations */
59     p_intf = _p_intf;
60     p_parent = _p_parent;
61     SetIcon( *p_intf->p_sys->p_icon );
62
63     /* Create a panel to put everything in */
64     wxPanel *panel = new wxPanel( this, -1 );
65     panel->SetAutoLayout( TRUE );
66     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
67     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
68
69 #if 0
70     /* Create the subtitles file textctrl */
71     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
72     wxStaticBox *file_box = new wxStaticBox( panel, -1,
73                                              wxU(_("Subtitles file")) );
74     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
75                                                         wxHORIZONTAL );
76     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
77     if( !psz_subsfile ) psz_subsfile = strdup("");
78     file_combo = new wxComboBox( panel, -1, wxL2U(psz_subsfile),
79                                  wxPoint(20,25), wxSize(300, -1) );
80     if( psz_subsfile ) free( psz_subsfile );
81     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
82                                             wxU(_("Browse...")) );
83     file_sizer->Add( file_combo, 1, wxALL, 5 );
84     file_sizer->Add( browse_button, 0, wxALL, 5 );
85     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
86     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
87 #endif
88
89     /* Subtitles encoding */
90     encoding_combo = NULL;
91     module_config_t *p_item =
92         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
93     if( p_item )
94     {
95         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
96         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
97                                                 wxU(_("Subtitles encoding")) );
98         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
99                                                             wxHORIZONTAL );
100         wxStaticText *label =
101             new wxStaticText(panel, -1, wxU(p_item->psz_text));
102         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
103                                          wxDefaultPosition, wxDefaultSize,
104                                          0, NULL, wxCB_READONLY );
105
106         /* build a list of available options */
107         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
108              i_index++ )
109         {
110             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
111             if( p_item->psz_value && !strcmp( p_item->psz_value,
112                                               p_item->ppsz_list[i_index] ) )
113                 encoding_combo->SetSelection( i_index );
114         }
115
116         if( p_item->psz_value )
117         encoding_combo->SetValue( wxU(p_item->psz_value) );
118         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
119
120         enc_sizer->Add( label, 0, wxALL | wxALIGN_CENTER, 5 );
121         enc_sizer->Add( encoding_combo, 0, wxEXPAND | wxALL | wxALIGN_CENTER, 5 );
122         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
123         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
124     }
125
126     /* Misc Subtitles options */
127     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
128     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
129                                              wxU(_("Subtitles options")) );
130
131     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
132                                                          wxVERTICAL );
133
134     wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
135
136     /* Font size */
137     p_item =
138         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
139     if( p_item )
140     {
141         wxBoxSizer *size_sizer = new wxBoxSizer( wxHORIZONTAL );
142         wxStaticText *label =
143             new wxStaticText(panel, -1, wxU(p_item->psz_text));
144         size_combo = new wxComboBox( panel, -1, wxT(""),
145                                      wxDefaultPosition, wxDefaultSize,
146                                      0, NULL, wxCB_READONLY );
147
148         /* build a list of available options */
149         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
150         {
151             size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
152                                 (void *)p_item->pi_list[i_index] );
153             if( p_item->i_value == p_item->pi_list[i_index] )
154             {
155                 size_combo->SetSelection( i_index );
156                 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
157             }
158         }
159
160         size_combo->SetToolTip( wxU(p_item->psz_longtext) );
161
162         size_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
163         size_sizer->Add( size_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
164         grid_sizer->Add( size_sizer, 1, wxEXPAND | wxALL, 5 );
165     }
166
167     p_item =
168         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
169     if( p_item )
170     {
171         wxBoxSizer *align_sizer = new wxBoxSizer( wxHORIZONTAL );
172         wxStaticText *label =
173             new wxStaticText(panel, -1, wxU(p_item->psz_text));
174         align_combo = new wxComboBox( panel, -1, wxT(""),
175                                      wxDefaultPosition, wxDefaultSize,
176                                      0, NULL, wxCB_READONLY );
177
178         /* build a list of available options */
179         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
180         {
181             align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
182                                 (void *)p_item->pi_list[i_index] );
183             if( p_item->i_value == p_item->pi_list[i_index] )
184             {
185                 align_combo->SetSelection( i_index );
186                 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
187             }
188         }
189
190         align_combo->SetToolTip( wxU(p_item->psz_longtext) );
191
192         align_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
193         align_sizer->Add( align_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
194         grid_sizer->Add( align_sizer, 1, wxEXPAND | wxALL, 5 );
195     }
196
197     misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
198
199     grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
200
201     wxStaticText *label =
202         new wxStaticText(panel, -1, wxU(_("Frames per second")));
203
204     float f_fps = config_GetFloat( p_intf, "sub-fps" );
205     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
206     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
207     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
208                                    wxDefaultPosition, wxDefaultSize,
209                                    wxSP_ARROW_KEYS,
210                                    0, 16000, (int)f_fps );
211     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
212                "It will only work with MicroDVD and SubRIP subtitles.")) );
213     grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
214     grid_sizer->Add( fps_spinctrl, 0,wxALIGN_CENTER, 5 );
215
216
217     wxStaticText *label_delay =
218         new wxStaticText(panel, -1, wxU(_("Delay")));
219
220     int i_delay = config_GetInt( p_intf, "sub-delay" );
221     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
222     wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
223     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
224                                      wxDefaultPosition, wxDefaultSize,
225                                      wxSP_ARROW_KEYS,
226                                      -30000, 30000, i_delay );
227     delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
228
229     grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
230     grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
231
232     misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
233
234     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
235
236     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
237
238     /* Separation */
239     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
240
241     /* Create the buttons */
242     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
243     ok_button->SetDefault();
244     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
245                                             wxU(_("Cancel")) );
246
247     /* Place everything in sizers */
248     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
249     button_sizer->Add( ok_button, 0, wxALL, 5 );
250     button_sizer->Add( cancel_button, 0, wxALL, 5 );
251     button_sizer->Layout();
252
253     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
254     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
255                       wxALL, 5 );
256     panel_sizer->Layout();
257     panel->SetSizerAndFit( panel_sizer );
258     main_sizer->Add( panel, 1, wxGROW, 0 );
259     main_sizer->Layout();
260     SetSizerAndFit( main_sizer );
261 }
262
263 SubsFileDialog::~SubsFileDialog()
264 {
265 }
266
267 /*****************************************************************************
268  * Private methods.
269  *****************************************************************************/
270
271 /*****************************************************************************
272  * Events methods.
273  *****************************************************************************/
274 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
275 {
276     EndModal( wxID_OK );
277 }
278
279 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
280 {
281     EndModal( wxID_CANCEL );
282 }
283
284 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
285 {
286 #if 0
287         wxFileDialog dialog( this, wxU(_("Open file")),
288                          wxT(""), wxT(""), wxT("*"), wxOPEN );
289
290     if( dialog.ShowModal() == wxID_OK )
291     {
292         file_combo->SetValue( dialog.GetPath() );
293     }
294 #endif
295 }