]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/subtitles.cpp
contrib/makefile: add libmpcdec (Musepack) to win contribs
[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     /* Create the subtitles file textctrl */
70     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
71     wxStaticBox *file_box = new wxStaticBox( panel, -1,
72                                              wxU(_("Subtitles file")) );
73     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
74                                                         wxHORIZONTAL );
75     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
76     if( !psz_subsfile ) psz_subsfile = strdup("");
77     file_combo = new wxComboBox( panel, -1, wxL2U(psz_subsfile),
78                                  wxPoint(20,25), wxSize(300, -1) );
79     if( psz_subsfile ) free( psz_subsfile );
80     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
81                                             wxU(_("Browse...")) );
82     file_sizer->Add( file_combo, 1, wxALL, 5 );
83     file_sizer->Add( browse_button, 0, wxALL, 5 );
84     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
85     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
86
87     /* Subtitles encoding */
88     encoding_combo = NULL;
89     module_config_t *p_item =
90         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
91     if( p_item )
92     {
93         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
94         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
95                                                 wxU(_("Subtitles encoding")) );
96         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
97                                                             wxHORIZONTAL );
98         wxStaticText *label =
99             new wxStaticText(panel, -1, wxU(p_item->psz_text));
100         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
101                                          wxDefaultPosition, wxDefaultSize,
102                                          0, NULL, wxCB_READONLY );
103
104         /* build a list of available options */
105         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
106              i_index++ )
107         {
108             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
109             if( p_item->psz_value && !strcmp( p_item->psz_value,
110                                               p_item->ppsz_list[i_index] ) )
111                 encoding_combo->SetSelection( i_index );
112         }
113
114         if( p_item->psz_value )
115         encoding_combo->SetValue( wxU(p_item->psz_value) );
116         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
117
118         enc_sizer->Add( label, 0, wxALL | wxALIGN_CENTER, 5 );
119         enc_sizer->Add( encoding_combo, 0, wxEXPAND | wxALL | wxALIGN_CENTER, 5 );
120         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
121         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
122     }
123
124     /* Misc Subtitles options */
125     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
126     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
127                                              wxU(_("Subtitles options")) );
128
129     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
130                                                          wxVERTICAL );
131
132     wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
133
134     /* Font size */
135     p_item =
136         config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
137     if( p_item )
138     {
139         wxBoxSizer *size_sizer = new wxBoxSizer( wxHORIZONTAL );
140         wxStaticText *label =
141             new wxStaticText(panel, -1, wxU(p_item->psz_text));
142         size_combo = new wxComboBox( panel, -1, wxT(""),
143                                      wxDefaultPosition, wxDefaultSize,
144                                      0, NULL, wxCB_READONLY );
145
146         /* build a list of available options */
147         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
148         {
149             size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
150                                 (void *)p_item->pi_list[i_index] );
151             if( p_item->i_value == p_item->pi_list[i_index] )
152             {
153                 size_combo->SetSelection( i_index );
154                 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
155             }
156         }
157
158         size_combo->SetToolTip( wxU(p_item->psz_longtext) );
159
160         size_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
161         size_sizer->Add( size_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
162         grid_sizer->Add( size_sizer, 1, wxEXPAND | wxALL, 5 );
163     }
164
165     p_item =
166         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
167     if( p_item )
168     {
169         wxBoxSizer *align_sizer = new wxBoxSizer( wxHORIZONTAL );
170         wxStaticText *label =
171             new wxStaticText(panel, -1, wxU(p_item->psz_text));
172         align_combo = new wxComboBox( panel, -1, wxT(""),
173                                      wxDefaultPosition, wxDefaultSize,
174                                      0, NULL, wxCB_READONLY );
175
176         /* build a list of available options */
177         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
178         {
179             align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
180                                 (void *)p_item->pi_list[i_index] );
181             if( p_item->i_value == p_item->pi_list[i_index] )
182             {
183                 align_combo->SetSelection( i_index );
184                 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
185             }
186         }
187
188         align_combo->SetToolTip( wxU(p_item->psz_longtext) );
189
190         align_sizer->Add( label, 0,  wxRIGHT | wxALIGN_CENTER, 5 );
191         align_sizer->Add( align_combo, 0, wxLEFT | wxALIGN_CENTER, 5 );
192         grid_sizer->Add( align_sizer, 1, wxEXPAND | wxALL, 5 );
193     }
194
195     misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
196
197     grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
198
199     wxStaticText *label =
200         new wxStaticText(panel, -1, wxU(_("Frames per second")));
201
202     float f_fps = config_GetFloat( p_intf, "sub-fps" );
203     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
204     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
205     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
206                                    wxDefaultPosition, wxDefaultSize,
207                                    wxSP_ARROW_KEYS,
208                                    0, 16000, (int)f_fps );
209     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
210                "It will only work with MicroDVD and SubRIP subtitles.")) );
211     grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
212     grid_sizer->Add( fps_spinctrl, 0,wxALIGN_CENTER, 5 );
213
214
215     wxStaticText *label_delay =
216         new wxStaticText(panel, -1, wxU(_("Delay")));
217
218     int i_delay = config_GetInt( p_intf, "sub-delay" );
219     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
220     wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
221     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
222                                      wxDefaultPosition, wxDefaultSize,
223                                      wxSP_ARROW_KEYS,
224                                      -30000, 30000, i_delay );
225     delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
226
227     grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
228     grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
229
230     misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
231
232     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
233
234     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
235
236     /* Separation */
237     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
238
239     /* Create the buttons */
240     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
241     ok_button->SetDefault();
242     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
243                                             wxU(_("Cancel")) );
244
245     /* Place everything in sizers */
246     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
247     button_sizer->Add( ok_button, 0, wxALL, 5 );
248     button_sizer->Add( cancel_button, 0, wxALL, 5 );
249     button_sizer->Layout();
250
251     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
252     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
253                       wxALL, 5 );
254     panel_sizer->Layout();
255     panel->SetSizerAndFit( panel_sizer );
256     main_sizer->Add( panel, 1, wxGROW, 0 );
257     main_sizer->Layout();
258     SetSizerAndFit( main_sizer );
259 }
260
261 SubsFileDialog::~SubsFileDialog()
262 {
263 }
264
265 /*****************************************************************************
266  * Private methods.
267  *****************************************************************************/
268
269 /*****************************************************************************
270  * Events methods.
271  *****************************************************************************/
272 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
273 {
274     EndModal( wxID_OK );
275 }
276
277 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
278 {
279     EndModal( wxID_CANCEL );
280 }
281
282 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
283 {
284     wxFileDialog dialog( this, wxU(_("Open file")),
285                          wxT(""), wxT(""), wxT("*"), wxOPEN );
286
287     if( dialog.ShowModal() == wxID_OK )
288     {
289         file_combo->SetValue( dialog.GetPath() );
290     }
291 }