1 /*****************************************************************************
2 * subtitles.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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 #include "dialogs/subtitles.hpp"
25 #include <wx/combobox.h>
26 #include <wx/statline.h>
27 #include <wx/spinctrl.h>
30 # define wxRB_SINGLE 0
33 /*****************************************************************************
35 *****************************************************************************/
37 /* IDs for the controls and the menu commands */
40 FileBrowse_Event = wxID_HIGHEST,
43 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
45 EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
46 EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
47 EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
51 /*****************************************************************************
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 )
61 SetIcon( *p_intf->p_sys->p_icon );
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 );
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,
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) );
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 );
89 /* Subtitles encoding */
90 encoding_combo = NULL;
91 module_config_t *p_item =
92 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
95 wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
96 wxStaticBox *enc_box = new wxStaticBox( panel, -1,
98 wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
100 wxStaticText *label =
101 new wxStaticText(panel, -1, wxU(p_item->psz_text));
102 encoding_combo = new wxComboBox( panel, -1, wxU(p_item->value.psz),
103 wxDefaultPosition, wxDefaultSize,
104 0, NULL, wxCB_READONLY );
106 /* build a list of available options */
107 for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
110 encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
111 if( p_item->value.psz && !strcmp( p_item->value.psz,
112 p_item->ppsz_list[i_index] ) )
113 encoding_combo->SetSelection( i_index );
116 if( p_item->value.psz )
117 encoding_combo->SetValue( wxU(p_item->value.psz) );
118 encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
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 );
126 /* Misc Subtitles options */
127 wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
128 wxStaticBox *misc_box = new wxStaticBox( panel, -1,
131 wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
134 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 1, 20 );
138 config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
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 );
148 /* build a list of available options */
149 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
151 size_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
152 (void *)p_item->pi_list[i_index] );
153 if( p_item->value.i == p_item->pi_list[i_index] )
155 size_combo->SetSelection( i_index );
156 size_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
160 size_combo->SetToolTip( wxU(p_item->psz_longtext) );
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 );
168 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
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 );
178 /* build a list of available options */
179 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
181 align_combo->Append( wxU(p_item->ppsz_list_text[i_index]),
182 (void *)p_item->pi_list[i_index] );
183 if( p_item->value.i == p_item->pi_list[i_index] )
185 align_combo->SetSelection( i_index );
186 align_combo->SetValue(wxU(p_item->ppsz_list_text[i_index]));
190 align_combo->SetToolTip( wxU(p_item->psz_longtext) );
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 );
197 misc_sizer->Add( grid_sizer, 1, wxEXPAND | wxALL , 5 );
199 grid_sizer = new wxFlexGridSizer( 4, 1, 20 );
201 wxStaticText *label =
202 new wxStaticText(panel, -1, wxU(_("Frames per second")));
204 fps_ctrl = new wxTextCtrl( panel, -1,
205 wxString::Format(wxT("%.3f"),
206 config_GetFloat( p_intf, "sub-fps" )),
207 wxDefaultPosition, wxDefaultSize);
208 fps_ctrl->SetToolTip( wxU(_("Override frames per second. "
209 "It will only work with MicroDVD and SubRIP subtitles.")) );
210 grid_sizer->Add( label, 0, wxALIGN_CENTER, 5 );
211 grid_sizer->Add( fps_ctrl, 0,wxALIGN_CENTER, 5 );
214 wxStaticText *label_delay =
215 new wxStaticText(panel, -1, wxU(_("Delay")));
217 int i_delay = config_GetInt( p_intf, "sub-delay" );
218 /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
219 wxString format_delay(wxString::Format(wxT("%i"), i_delay ));
220 delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
221 wxDefaultPosition, wxDefaultSize,
223 -70000, 70000, i_delay );
224 delay_spinctrl->SetToolTip( wxU(_("Set subtitle delay (in 1/10s)" ) ) );
226 grid_sizer->Add( label_delay , 0, wxALIGN_CENTER, 5 );
227 grid_sizer->Add( delay_spinctrl, 0, wxALIGN_CENTER, 5 );
229 misc_sizer->Add( grid_sizer, 0, wxALL, 5 );
231 misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
233 panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
236 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
238 /* Create the buttons */
239 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("&OK")) );
240 ok_button->SetDefault();
241 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
244 /* Place everything in sizers */
245 wxStdDialogButtonSizer *button_sizer = new wxStdDialogButtonSizer;
246 button_sizer->AddButton( ok_button );
247 button_sizer->AddButton( cancel_button );
248 button_sizer->Realize();
250 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
251 panel_sizer->Add( button_sizer, 0, wxEXPAND | wxALL, 5 );
252 panel_sizer->Layout();
253 panel->SetSizerAndFit( panel_sizer );
254 main_sizer->Add( panel, 1, wxGROW, 0 );
255 main_sizer->Layout();
256 SetSizerAndFit( main_sizer );
259 SubsFileDialog::~SubsFileDialog()
263 /*****************************************************************************
265 *****************************************************************************/
267 /*****************************************************************************
269 *****************************************************************************/
270 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
275 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
277 EndModal( wxID_CANCEL );
280 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
283 wxFileDialog dialog( this, wxU(_("Open file")),
284 wxT(""), wxT(""), wxT("*"), wxOPEN );
286 if( dialog.ShowModal() == wxID_OK )
288 file_combo->SetValue( dialog.GetPath() );