]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/subtitles.cpp
* fixed an internal error with stupid gcc2.95
[vlc] / modules / gui / wxwindows / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: subtitles.cpp,v 1.5 2003/08/20 21:59:01 asmax Exp $
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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/textctrl.h>
45 #include <wx/combobox.h>
46 #include <wx/spinctrl.h>
47 #include <wx/statline.h>
48
49 #include <vlc/intf.h>
50
51 #if defined MODULE_NAME_IS_skins
52 #   include "../skins/src/skin_common.h"
53 #endif
54
55 #include "wxwindows.h"
56
57 #ifndef wxRB_SINGLE
58 #   define wxRB_SINGLE 0
59 #endif
60
61 /*****************************************************************************
62  * Event Table.
63  *****************************************************************************/
64
65 /* IDs for the controls and the menu commands */
66 enum
67 {
68     FileBrowse_Event = wxID_HIGHEST,
69 };
70
71 BEGIN_EVENT_TABLE(SubsFileDialog, wxDialog)
72     /* Button events */
73     EVT_BUTTON(wxID_OK, SubsFileDialog::OnOk)
74     EVT_BUTTON(wxID_CANCEL, SubsFileDialog::OnCancel)
75     EVT_BUTTON(FileBrowse_Event, SubsFileDialog::OnFileBrowse)
76
77 END_EVENT_TABLE()
78
79 /*****************************************************************************
80  * Constructor.
81  *****************************************************************************/
82 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
83     wxDialog( _p_parent, -1, wxU(_("Open Subtitles File")),
84               wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
85 {
86     /* Initializations */
87     p_intf = _p_intf;
88     p_parent = _p_parent;
89     SetIcon( *p_intf->p_sys->p_icon );
90
91     /* Create a panel to put everything in */
92     wxPanel *panel = new wxPanel( this, -1 );
93     panel->SetAutoLayout( TRUE );
94     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
95     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
96
97     /* Create the subtitles file textctrl */
98     wxBoxSizer *file_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
99     wxStaticBox *file_box = new wxStaticBox( panel, -1,
100                                              wxU(_("Subtitles file")) );
101     wxStaticBoxSizer *file_sizer = new wxStaticBoxSizer( file_box,
102                                                         wxHORIZONTAL );
103     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
104     file_combo = new wxComboBox( panel, -1,
105                                  psz_subsfile ? wxU(psz_subsfile) : wxT(""),
106                                  wxPoint(20,25), wxSize(300, -1), 0, NULL );
107     if( psz_subsfile ) free( psz_subsfile );
108     wxButton *browse_button = new wxButton( panel, FileBrowse_Event,
109                                             wxU(_("Browse...")) );
110     file_sizer->Add( file_combo, 1, wxALL, 5 );
111     file_sizer->Add( browse_button, 0, wxALL, 5 );
112     file_sizer_sizer->Add( file_sizer, 1, wxEXPAND | wxALL, 5 );
113     panel_sizer->Add( file_sizer, 0, wxEXPAND | wxALL, 5 );
114
115     /* Subtitles encoding */
116     encoding_combo = NULL;
117     module_config_t *p_item =
118         config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
119     if( p_item )
120     {
121         wxBoxSizer *enc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
122         wxStaticBox *enc_box = new wxStaticBox( panel, -1,
123                                                 wxU(_("Subtitles encoding")) );
124         wxStaticBoxSizer *enc_sizer = new wxStaticBoxSizer( enc_box,
125                                                             wxHORIZONTAL );
126         wxStaticText *label =
127             new wxStaticText(panel, -1, wxU(p_item->psz_text));
128         encoding_combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
129                                          wxDefaultPosition, wxDefaultSize,
130                                          0, NULL, wxCB_READONLY | wxCB_SORT );
131
132         /* build a list of available options */
133         for( int i_index = 0; p_item->ppsz_list && p_item->ppsz_list[i_index];
134              i_index++ )
135         {
136             encoding_combo->Append( wxU(p_item->ppsz_list[i_index]) );
137             if( p_item->psz_value && !strcmp( p_item->psz_value,
138                                               p_item->ppsz_list[i_index] ) )
139                 encoding_combo->SetSelection( i_index );
140         }
141
142         if( p_item->psz_value )
143         encoding_combo->SetValue( wxU(p_item->psz_value) );
144         encoding_combo->SetToolTip( wxU(p_item->psz_longtext) );
145
146         enc_sizer->Add( label, 0, wxALL, 5 );
147         enc_sizer->Add( encoding_combo, 0, wxALL, 5 );
148         enc_sizer_sizer->Add( enc_sizer, 1, wxEXPAND | wxALL, 5 );
149         panel_sizer->Add( enc_sizer, 0, wxEXPAND | wxALL, 5 );
150     }
151
152     /* Misc Subtitles options */
153     wxBoxSizer *misc_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
154     wxStaticBox *misc_box = new wxStaticBox( panel, -1,
155                                              wxU(_("Subtitles options")) );
156     wxStaticBoxSizer *misc_sizer = new wxStaticBoxSizer( misc_box,
157                                                          wxHORIZONTAL );
158     wxStaticText *label =
159         new wxStaticText(panel, -1, wxU(_("Delay subtitles (in 1/10s)")));
160     int i_delay = config_GetInt( p_intf, "sub-delay" );
161     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
162     wxString format_delay(wxString::Format(wxT("%d"), i_delay));
163     delay_spinctrl = new wxSpinCtrl( panel, -1, format_delay,
164                                      wxDefaultPosition, wxDefaultSize,
165                                      wxSP_ARROW_KEYS,
166                                      -650000, 650000, i_delay );
167
168     misc_sizer->Add( label, 0, wxALL, 5 );
169     misc_sizer->Add( delay_spinctrl, 0, wxALL, 5 );
170
171     label = new wxStaticText(panel, -1, wxU(_("Frames per second")));
172
173     float f_fps = config_GetFloat( p_intf, "sub-fps" );
174     /* Outside the new wxSpinCtrl to avoid an internal error in gcc2.95 ! */
175     wxString format_fps(wxString::Format(wxT("%d"),(int)f_fps));
176     fps_spinctrl = new wxSpinCtrl( panel, -1, format_fps,
177                                    wxDefaultPosition, wxDefaultSize,
178                                    wxSP_ARROW_KEYS,
179                                    0, 16000, (int)f_fps );
180     fps_spinctrl->SetToolTip( wxU(_("Override frames per second. "
181                               "It will only work with MicroDVD subtitles.")) );
182     misc_sizer->Add( label, 0, wxALL, 5 );
183     misc_sizer->Add( fps_spinctrl, 0, wxALL, 5 );
184
185     misc_sizer_sizer->Add( misc_sizer, 1, wxEXPAND | wxALL, 5 );
186     panel_sizer->Add( misc_sizer, 0, wxEXPAND | wxALL, 5 );
187
188     /* Separation */
189     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
190
191     /* Create the buttons */
192     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
193     ok_button->SetDefault();
194     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
195                                             wxU(_("Cancel")) );
196
197     /* Place everything in sizers */
198     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
199     button_sizer->Add( ok_button, 0, wxALL, 5 );
200     button_sizer->Add( cancel_button, 0, wxALL, 5 );
201     button_sizer->Layout();
202
203     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
204     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
205                       wxALL, 5 );
206     panel_sizer->Layout();
207     panel->SetSizerAndFit( panel_sizer );
208     main_sizer->Add( panel, 1, wxGROW, 0 );
209     main_sizer->Layout();
210     SetSizerAndFit( main_sizer );
211 }
212
213 SubsFileDialog::~SubsFileDialog()
214 {
215 }
216
217 /*****************************************************************************
218  * Private methods.
219  *****************************************************************************/
220
221 /*****************************************************************************
222  * Events methods.
223  *****************************************************************************/
224 void SubsFileDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
225 {
226     EndModal( wxID_OK );
227 }
228
229 void SubsFileDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
230 {
231     EndModal( wxID_CANCEL );
232 }
233
234 void SubsFileDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
235 {
236     wxFileDialog dialog( this, wxU(_("Open file")),
237                          wxT(""), wxT(""), wxT("*"), wxOPEN );
238
239     if( dialog.ShowModal() == wxID_OK )
240     {
241         file_combo->SetValue( dialog.GetPath() );
242     }
243 }