1 /*****************************************************************************
\r
2 * dialogs.cpp: Handles all the different dialog boxes we provide.
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2003 VideoLAN
\r
5 * $Id: dialogs.cpp,v 1.9 2003/07/13 14:55:17 gbazin Exp $
\r
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License as published by
\r
11 * the Free Software Foundation; either version 2 of the License, or
\r
12 * (at your option) any later version.
\r
14 * This program is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU General Public License for more details.
\r
19 * You should have received a copy of the GNU General Public License
\r
20 * along with this program; if not, write to the Free Software
\r
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
\r
23 *****************************************************************************/
\r
25 //--- VLC -------------------------------------------------------------------
\r
26 #include <vlc/vlc.h>
\r
27 #include <vlc/intf.h>
\r
29 //--- SKIN ------------------------------------------------------------------
\r
30 #include "../os_api.h"
\r
34 #include "../os_theme.h"
\r
35 #include "themeloader.h"
\r
37 #include "vlcproc.h"
\r
38 #include "skin_common.h"
\r
39 #include "dialogs.h"
\r
41 /* Callback prototype */
\r
42 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
\r
43 vlc_value_t old_val, vlc_value_t new_val, void *param );
\r
45 #if defined(MODULE_NAME_IS_basic_skins)
\r
48 Dialogs::Dialogs( intf_thread_t *_p_intf ){}
\r
50 Dialogs::~Dialogs(){}
\r
52 void Dialogs::ShowOpen( bool b_play ){}
\r
53 void Dialogs::ShowOpenSkin(){}
\r
54 void Dialogs::ShowMessages(){}
\r
55 void Dialogs::ShowPrefs(){}
\r
56 void Dialogs::ShowFileInfo(){}
\r
57 void Dialogs::ShowPopup(){}
\r
59 #else // !MODULE_NAME_IS_basic_skins
\r
61 #include "../../wxwindows/wxwindows.h"
\r
62 #include "../../../../share/vlc32x32.xpm" // include the graphic icon
\r
64 #define ShowOpen_Event 0
\r
65 #define ShowOpenSkin_Event 1
\r
66 #define ShowMessages_Event 2
\r
67 #define ShowPrefs_Event 3
\r
68 #define ShowFileInfo_Event 4
\r
69 #define ShowPopup_Event 5
\r
70 #define ExitThread_Event 99
\r
72 //---------------------------------------------------------------------------
\r
73 // Local classes declarations.
\r
74 //---------------------------------------------------------------------------
\r
76 DEFINE_EVENT_TYPE(wxEVT_DIALOG)
\r
78 class Instance: public wxApp
\r
82 Instance( intf_thread_t *_p_intf );
\r
88 intf_thread_t *p_intf;
\r
90 DECLARE_EVENT_TABLE();
\r
93 BEGIN_EVENT_TABLE(Instance, wxApp)
\r
94 EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)
\r
95 EVT_COMMAND(ShowOpenSkin_Event, wxEVT_DIALOG, Dialogs::OnShowOpenSkin)
\r
96 EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)
\r
97 EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)
\r
98 EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)
\r
99 EVT_COMMAND(ShowPopup_Event, wxEVT_DIALOG, Dialogs::OnShowPopup)
\r
100 EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)
\r
103 //---------------------------------------------------------------------------
\r
104 // Implementation of Instance class
\r
105 //---------------------------------------------------------------------------
\r
106 Instance::Instance( )
\r
110 Instance::Instance( intf_thread_t *_p_intf )
\r
116 IMPLEMENT_APP_NO_MAIN(Instance)
\r
118 bool Instance::OnInit()
\r
120 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
\r
122 // Create all the dialog boxes
\r
123 p_intf->p_sys->p_dialogs->OpenDlg =
\r
124 new OpenDialog( p_intf, NULL, FILE_ACCESS );
\r
125 p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );
\r
126 p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );
\r
127 p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );
\r
129 // OK, initialization is over, now the other thread can go on working...
\r
130 vlc_thread_ready( p_intf->p_sys->p_dialogs->p_thread );
\r
132 /* Register callback for the intf-popupmenu variable */
\r
133 playlist_t *p_playlist =
\r
134 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
\r
136 if( p_playlist != NULL )
\r
138 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
\r
139 p_intf->p_sys->p_dialogs );
\r
140 vlc_object_release( p_playlist );
\r
143 /* Intercept all menu events in our custom event handler */
\r
144 p_intf->p_sys->p_dialogs->OpenDlg->PushEventHandler(
\r
145 new MenuEvtHandler( p_intf, NULL ) );
\r
150 int Instance::OnExit()
\r
152 // Delete evertything
\r
153 delete p_intf->p_sys->p_dialogs->FileInfoDlg;
\r
154 delete p_intf->p_sys->p_dialogs->PrefsDlg;
\r
155 delete p_intf->p_sys->p_dialogs->MessagesDlg;
\r
156 delete p_intf->p_sys->p_dialogs->OpenDlg;
\r
157 delete p_intf->p_sys->p_icon;
\r
162 //---------------------------------------------------------------------------
\r
163 #if !defined(__BUILTIN__) && defined( WIN32 )
\r
164 HINSTANCE hInstance = 0;
\r
165 extern "C" BOOL WINAPI
\r
166 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
\r
168 hInstance = (HINSTANCE)hModule;
\r
173 //---------------------------------------------------------------------------
\r
175 // We create all wxWindows dialogs in a separate thread because we don't want
\r
176 // any interaction with our own message loop
\r
177 //---------------------------------------------------------------------------
\r
178 void SkinsDialogsThread( dialogs_thread_t *p_thread )
\r
180 #if !defined( WIN32 )
\r
181 static char *p_args[] = { "" };
\r
183 intf_thread_t *p_intf = p_thread->p_intf;
\r
185 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
\r
186 wxTheApp = new Instance( p_intf );
\r
188 #if defined( WIN32 )
\r
189 #if !defined(__BUILTIN__)
\r
190 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
\r
192 wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );
\r
195 wxEntry( 1, p_args );
\r
201 //---------------------------------------------------------------------------
\r
202 // Implementation of Dialogs class
\r
203 //---------------------------------------------------------------------------
\r
204 Dialogs::Dialogs( intf_thread_t *_p_intf )
\r
207 p_intf->p_sys->p_dialogs = this;
\r
208 b_popup_change = VLC_FALSE;
\r
210 p_thread = (dialogs_thread_t *)vlc_object_create( p_intf,
\r
211 sizeof(dialogs_thread_t) );
\r
212 p_thread->p_intf = p_intf;
\r
214 // Create a new thread for wxWindows
\r
215 if( vlc_thread_create( p_thread, "Skins Dialogs Thread",
\r
216 SkinsDialogsThread, 0, VLC_TRUE ) )
\r
219 msg_Err( p_intf, "cannot create SkinsDialogsThread" );
\r
223 Dialogs::~Dialogs()
\r
225 wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );
\r
226 event.SetClientData( this );
\r
228 wxTheApp->AddPendingEvent( event );
\r
230 vlc_thread_join( p_thread );
\r
233 void Dialogs::ShowOpen( bool b_play )
\r
235 wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );
\r
236 event.SetClientData( this );
\r
237 event.SetInt( b_play );
\r
239 wxTheApp->AddPendingEvent( event );
\r
242 void Dialogs::ShowOpenSkin()
\r
244 wxCommandEvent event( wxEVT_DIALOG, ShowOpenSkin_Event );
\r
245 event.SetClientData( this );
\r
247 wxTheApp->AddPendingEvent( event );
\r
250 void Dialogs::ShowMessages()
\r
252 wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );
\r
253 event.SetClientData( this );
\r
255 wxTheApp->AddPendingEvent( event );
\r
258 void Dialogs::ShowPrefs()
\r
260 wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );
\r
261 event.SetClientData( this );
\r
263 wxTheApp->AddPendingEvent( event );
\r
266 void Dialogs::ShowFileInfo()
\r
268 wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );
\r
269 event.SetClientData( this );
\r
271 wxTheApp->AddPendingEvent( event );
\r
274 void Dialogs::ShowPopup()
\r
276 wxCommandEvent event( wxEVT_DIALOG, ShowPopup_Event );
\r
277 event.SetClientData( this );
\r
279 wxTheApp->AddPendingEvent( event );
\r
282 void Dialogs::OnShowOpen( wxCommandEvent& event )
\r
284 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
285 bool b_play = event.GetInt() ? TRUE : FALSE;
\r
287 if( p_dialogs->OpenDlg->IsShown() ) return;
\r
289 if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )
\r
294 // Check if playlist is available
\r
295 playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;
\r
296 if( p_playlist == NULL )
\r
304 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
306 playlist_Add( p_playlist,
\r
307 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
308 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
\r
310 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
\r
315 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
317 playlist_Add( p_playlist,
\r
318 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
319 PLAYLIST_APPEND, PLAYLIST_END );
\r
323 // Refresh interface !
\r
324 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
\r
325 ->PostSynchroMessage();
\r
330 void Dialogs::OnShowOpenSkin( wxCommandEvent& event )
\r
332 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
333 intf_thread_t *p_intf = p_dialogs->p_intf;
\r
335 wxFileDialog dialog( NULL,
\r
336 wxU(_("Open a skin file")), wxT(""), wxT(""),
\r
337 wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
\r
338 "All files|*.*"), wxOPEN );
\r
340 if( dialog.ShowModal() == wxID_OK )
\r
342 p_intf->p_sys->p_new_theme_file =
\r
343 new char[strlen(dialog.GetPath().mb_str()) + 1];
\r
345 strcpy( p_intf->p_sys->p_new_theme_file,
\r
346 dialog.GetPath().mb_str() );
\r
348 // Tell vlc to change skin after hiding interface
\r
349 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
\r
353 void Dialogs::OnShowMessages( wxCommandEvent& event )
\r
355 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
356 p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );
\r
359 void Dialogs::OnShowPrefs( wxCommandEvent& event )
\r
361 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
362 p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );
\r
365 void Dialogs::OnShowFileInfo( wxCommandEvent& event )
\r
367 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
368 p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );
\r
371 void Dialogs::OnShowPopup( wxCommandEvent& event )
\r
373 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
375 wxPoint mousepos = wxGetMousePosition();
\r
377 wxMouseEvent mouseevent = wxMouseEvent( wxEVT_RIGHT_UP );
\r
378 mouseevent.m_x = p_dialogs->OpenDlg->ScreenToClient(mousepos).x;
\r
379 mouseevent.m_y = p_dialogs->OpenDlg->ScreenToClient(mousepos).y;
\r
381 ::PopupMenu( p_dialogs->p_intf,
\r
382 p_dialogs->OpenDlg, mouseevent.GetPosition() );
\r
385 void Dialogs::OnExitThread( wxCommandEvent& event )
\r
387 wxTheApp->ExitMainLoop();
\r
389 #endif // MODULE_NAME_IS_basic_skins
\r
391 /*****************************************************************************
\r
392 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
\r
393 * We don't show the menu directly here because we don't want the
\r
394 * caller to block for a too long time.
\r
395 *****************************************************************************/
\r
396 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
\r
397 vlc_value_t old_val, vlc_value_t new_val, void *param )
\r
399 #if !defined(MODULE_NAME_IS_basic_skins)
\r
400 Dialogs *p_dialogs = (Dialogs *)param;
\r
402 p_dialogs->ShowPopup();
\r
405 return VLC_SUCCESS;
\r