]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/dialogs.cpp
* modules/gui/wxwindows/*: enable popup menu support in the "dialogs provider".
[vlc] / modules / gui / wxwindows / dialogs.cpp
1 /*****************************************************************************
2  * dialogs.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: dialogs.cpp,v 1.2 2003/07/17 18:58:23 gbazin 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 #include <vlc/aout.h>
34
35 #ifdef WIN32                                                 /* mingw32 hack */
36 #undef Yield
37 #undef CreateDialog
38 #endif
39
40 /* Let vlc take care of the i18n stuff */
41 #define WXINTL_NO_GETTEXT_MACRO
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45
46 #include <vlc/intf.h>
47 #include "stream_control.h"
48
49 #include "wxwindows.h"
50
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
53
54 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
55
56 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
57     /* Idle loop used to update some of the dialogs */
58     EVT_IDLE(DialogsProvider::OnIdle)
59
60     /* Custom wxDialog events */
61     EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
62     EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
63     EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
64     EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
65                 DialogsProvider::OnOpenFileSimple)
66
67     EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
68                 DialogsProvider::OnPlaylist)
69     EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
70                 DialogsProvider::OnMessages)
71     EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
72                 DialogsProvider::OnPreferences)
73     EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
74                 DialogsProvider::OnFileInfo)
75     EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
76                 DialogsProvider::OnPopupMenu)
77 END_EVENT_TABLE()
78
79 /*****************************************************************************
80  * Constructor.
81  *****************************************************************************/
82 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
83   :  wxFrame( p_parent, -1, wxT("") )
84 {
85     /* Initializations */
86     p_intf = _p_intf;
87     p_open_dialog = NULL;
88     p_file_dialog = NULL;
89     p_playlist_dialog = NULL;
90     p_messages_dialog = NULL;
91     p_fileinfo_dialog = NULL;
92     p_prefs_dialog = NULL;
93
94     /* Give our interface a nice little icon */
95     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
96
97     /* Create the messages dialog so it can begin storing logs */
98     p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
99
100     /* Intercept all menu events in our custom event handler */
101     PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
102 }
103
104 DialogsProvider::~DialogsProvider()
105 {
106     /* Clean up */
107     if( p_open_dialog )     delete p_open_dialog;
108     if( p_prefs_dialog )    p_prefs_dialog->Destroy();
109     if( p_file_dialog )     delete p_file_dialog;
110     if( p_playlist_dialog ) delete p_playlist_dialog;
111     if( p_messages_dialog ) delete p_messages_dialog;
112     if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
113
114     if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
115 }
116
117 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
118 {
119   /* Update the log window */
120   if( p_messages_dialog )
121     p_messages_dialog->UpdateLog();
122
123   /* Update the playlist */
124   if( p_playlist_dialog )
125     p_playlist_dialog->UpdatePlaylist();
126
127   /* Update the fileinfo windows */
128   if( p_fileinfo_dialog )
129     p_fileinfo_dialog->UpdateFileInfo();
130 }
131
132 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
133 {
134     /* Show/hide the playlist window */
135     if( !p_playlist_dialog )
136         p_playlist_dialog = new Playlist( p_intf, this );
137
138     if( p_playlist_dialog )
139     {
140         p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
141     }
142 }
143
144 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
145 {
146     /* Show/hide the log window */
147     if( !p_messages_dialog )
148         p_messages_dialog = new Messages( p_intf, this );
149
150     if( p_messages_dialog )
151     {
152         p_messages_dialog->Show( !p_messages_dialog->IsShown() );
153     }
154 }
155
156 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
157 {
158     /* Show/hide the file info window */
159     if( !p_fileinfo_dialog )
160         p_fileinfo_dialog = new FileInfo( p_intf, this );
161
162     if( p_fileinfo_dialog )
163     {
164         p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
165     }
166 }
167
168 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
169 {
170     /* Show/hide the open dialog */
171     if( !p_prefs_dialog )
172         p_prefs_dialog = new PrefsDialog( p_intf, this );
173
174     if( p_prefs_dialog )
175     {
176         p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
177     }
178 }
179
180 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
181 {
182     playlist_t *p_playlist =
183         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
184                                        FIND_ANYWHERE );
185     if( p_playlist == NULL )
186     {
187         return;
188     }
189
190     if( p_file_dialog == NULL )
191         p_file_dialog = new wxFileDialog( this, wxU(_("Open file")),
192             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
193
194     if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
195     {
196         wxArrayString paths;
197
198         p_file_dialog->GetPaths( paths );
199
200         for( size_t i = 0; i < paths.GetCount(); i++ )
201             if( event.GetInt() )
202                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
203                               PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
204                               PLAYLIST_END );
205             else
206                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
207                               PLAYLIST_APPEND, PLAYLIST_END );
208     }
209
210     vlc_object_release( p_playlist );
211 }
212
213 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
214 {
215     Open( FILE_ACCESS, event.GetInt() );
216 }
217
218 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
219 {
220     Open( DISC_ACCESS, event.GetInt() );
221 }
222
223 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
224 {
225     Open( NET_ACCESS, event.GetInt() );
226 }
227
228 void DialogsProvider::OnOpenSat( wxCommandEvent& event )
229 {
230     Open( SAT_ACCESS, event.GetInt() );
231 }
232
233 void DialogsProvider::Open( int i_access_method, int i_arg )
234 {
235     /* Show/hide the open dialog */
236     if( !p_open_dialog )
237         p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg );
238
239     if( p_open_dialog )
240     {
241         p_open_dialog->Show( i_access_method, i_arg );
242     }
243 }
244
245 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
246 {
247     wxPoint mousepos = wxGetMousePosition();
248
249 #if 0
250     wxMouseEvent event = wxMouseEvent( wxEVT_RIGHT_UP );
251     event.m_x = p_main_interface->ScreenToClient(mousepos).x;
252     event.m_y = p_main_interface->ScreenToClient(mousepos).y;
253 #endif
254
255     ::PopupMenu( p_intf, this, mousepos );
256
257 }