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.8 2003/06/28 13:04:52 sam 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
83 Instance( intf_thread_t *_p_intf, CallBackObjects *callback );
\r
85 Instance( intf_thread_t *_p_intf );
\r
92 intf_thread_t *p_intf;
\r
95 CallBackObjects *callbackobj;
\r
98 DECLARE_EVENT_TABLE();
\r
101 BEGIN_EVENT_TABLE(Instance, wxApp)
\r
102 EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)
\r
103 EVT_COMMAND(ShowOpenSkin_Event, wxEVT_DIALOG, Dialogs::OnShowOpenSkin)
\r
104 EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)
\r
105 EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)
\r
106 EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)
\r
107 EVT_COMMAND(ShowPopup_Event, wxEVT_DIALOG, Dialogs::OnShowPopup)
\r
108 EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)
\r
111 //---------------------------------------------------------------------------
\r
112 // Implementation of Instance class
\r
113 //---------------------------------------------------------------------------
\r
114 Instance::Instance( )
\r
119 Instance::Instance( intf_thread_t *_p_intf, CallBackObjects *callback )
\r
123 callbackobj = callback;
\r
126 Instance::Instance( intf_thread_t *_p_intf )
\r
133 IMPLEMENT_APP_NO_MAIN(Instance)
\r
135 bool Instance::OnInit()
\r
137 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
\r
140 // Set event callback. Yes, it's a big hack ;)
\r
141 gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
\r
144 // Create all the dialog boxes
\r
145 p_intf->p_sys->p_dialogs->OpenDlg =
\r
146 new OpenDialog( p_intf, NULL, FILE_ACCESS );
\r
147 p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );
\r
148 p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );
\r
149 p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );
\r
153 g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
\r
156 // OK, initialization is over, now the other thread can go on working...
\r
157 vlc_thread_ready( p_intf->p_sys->p_dialogs->p_thread );
\r
159 /* Register callback for the intf-popupmenu variable */
\r
160 playlist_t *p_playlist =
\r
161 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
\r
163 if( p_playlist != NULL )
\r
165 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
\r
166 p_intf->p_sys->p_dialogs );
\r
167 vlc_object_release( p_playlist );
\r
170 /* Intercept all menu events in our custom event handler */
\r
171 p_intf->p_sys->p_dialogs->OpenDlg->PushEventHandler(
\r
172 new MenuEvtHandler( p_intf, NULL ) );
\r
177 int Instance::OnExit()
\r
179 // Delete evertything
\r
180 delete p_intf->p_sys->p_dialogs->FileInfoDlg;
\r
181 delete p_intf->p_sys->p_dialogs->PrefsDlg;
\r
182 delete p_intf->p_sys->p_dialogs->MessagesDlg;
\r
183 delete p_intf->p_sys->p_dialogs->OpenDlg;
\r
184 delete p_intf->p_sys->p_icon;
\r
189 //---------------------------------------------------------------------------
\r
190 #if !defined(__BUILTIN__) && defined( WIN32 )
\r
191 HINSTANCE hInstance = 0;
\r
192 extern "C" BOOL WINAPI
\r
193 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
\r
195 hInstance = (HINSTANCE)hModule;
\r
200 //---------------------------------------------------------------------------
\r
202 // We create all wxWindows dialogs in a separate thread because we don't want
\r
203 // any interaction with our own message loop
\r
204 //---------------------------------------------------------------------------
\r
205 void SkinsDialogsThread( dialogs_thread_t *p_thread )
\r
207 #if !defined( WIN32 )
\r
208 static char *p_args[] = { "" };
\r
210 intf_thread_t *p_intf = p_thread->p_intf;
\r
212 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
\r
213 wxTheApp = new Instance( p_intf );
\r
215 #if defined( WIN32 )
\r
216 #if !defined(__BUILTIN__)
\r
217 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
\r
219 wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );
\r
222 wxEntry( 1, p_args );
\r
228 //---------------------------------------------------------------------------
\r
229 // Implementation of Dialogs class
\r
230 //---------------------------------------------------------------------------
\r
231 Dialogs::Dialogs( intf_thread_t *_p_intf )
\r
234 p_intf->p_sys->p_dialogs = this;
\r
235 b_popup_change = VLC_FALSE;
\r
237 p_thread = (dialogs_thread_t *)vlc_object_create( p_intf,
\r
238 sizeof(dialogs_thread_t) );
\r
239 p_thread->p_intf = p_intf;
\r
241 // Create a new thread for wxWindows
\r
242 if( vlc_thread_create( p_thread, "Skins Dialogs Thread",
\r
243 SkinsDialogsThread, 0, VLC_TRUE ) )
\r
246 msg_Err( p_intf, "cannot create SkinsDialogsThread" );
\r
250 Dialogs::~Dialogs()
\r
252 wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );
\r
253 event.SetClientData( this );
\r
255 wxTheApp->AddPendingEvent( event );
\r
257 vlc_thread_join( p_thread );
\r
260 void Dialogs::ShowOpen( bool b_play )
\r
262 wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );
\r
263 event.SetClientData( this );
\r
264 event.SetInt( b_play );
\r
266 wxTheApp->AddPendingEvent( event );
\r
269 void Dialogs::ShowOpenSkin()
\r
271 wxCommandEvent event( wxEVT_DIALOG, ShowOpenSkin_Event );
\r
272 event.SetClientData( this );
\r
274 wxTheApp->AddPendingEvent( event );
\r
277 void Dialogs::ShowMessages()
\r
279 wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );
\r
280 event.SetClientData( this );
\r
282 wxTheApp->AddPendingEvent( event );
\r
285 void Dialogs::ShowPrefs()
\r
287 wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );
\r
288 event.SetClientData( this );
\r
290 wxTheApp->AddPendingEvent( event );
\r
293 void Dialogs::ShowFileInfo()
\r
295 wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );
\r
296 event.SetClientData( this );
\r
298 wxTheApp->AddPendingEvent( event );
\r
301 void Dialogs::ShowPopup()
\r
303 wxCommandEvent event( wxEVT_DIALOG, ShowPopup_Event );
\r
304 event.SetClientData( this );
\r
306 wxTheApp->AddPendingEvent( event );
\r
309 void Dialogs::OnShowOpen( wxCommandEvent& event )
\r
311 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
312 bool b_play = event.GetInt() ? TRUE : FALSE;
\r
314 if( p_dialogs->OpenDlg->IsShown() ) return;
\r
316 if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )
\r
321 // Check if playlist is available
\r
322 playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;
\r
323 if( p_playlist == NULL )
\r
331 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
333 playlist_Add( p_playlist,
\r
334 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
335 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
\r
337 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
\r
342 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
344 playlist_Add( p_playlist,
\r
345 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
346 PLAYLIST_APPEND, PLAYLIST_END );
\r
350 // Refresh interface !
\r
351 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
\r
352 ->PostSynchroMessage();
\r
357 void Dialogs::OnShowOpenSkin( wxCommandEvent& event )
\r
359 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
360 intf_thread_t *p_intf = p_dialogs->p_intf;
\r
362 wxFileDialog dialog( NULL,
\r
363 wxU(_("Open a skin file")), wxT(""), wxT(""),
\r
364 wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
\r
365 "All files|*.*"), wxOPEN );
\r
367 if( dialog.ShowModal() == wxID_OK )
\r
369 p_intf->p_sys->p_new_theme_file =
\r
370 new char[strlen(dialog.GetPath().mb_str()) + 1];
\r
372 strcpy( p_intf->p_sys->p_new_theme_file,
\r
373 dialog.GetPath().mb_str() );
\r
375 // Tell vlc to change skin after hiding interface
\r
376 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
\r
380 void Dialogs::OnShowMessages( wxCommandEvent& event )
\r
382 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
383 p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );
\r
386 void Dialogs::OnShowPrefs( wxCommandEvent& event )
\r
388 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
389 p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );
\r
392 void Dialogs::OnShowFileInfo( wxCommandEvent& event )
\r
394 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
395 p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );
\r
398 void Dialogs::OnShowPopup( wxCommandEvent& event )
\r
400 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
402 wxPoint mousepos = wxGetMousePosition();
\r
404 wxMouseEvent mouseevent = wxMouseEvent( wxEVT_RIGHT_UP );
\r
405 mouseevent.m_x = p_dialogs->OpenDlg->ScreenToClient(mousepos).x;
\r
406 mouseevent.m_y = p_dialogs->OpenDlg->ScreenToClient(mousepos).y;
\r
408 ::PopupMenu( p_dialogs->p_intf,
\r
409 p_dialogs->OpenDlg, mouseevent.GetPosition() );
\r
412 void Dialogs::OnExitThread( wxCommandEvent& event )
\r
414 wxTheApp->ExitMainLoop();
\r
416 #endif // MODULE_NAME_IS_basic_skins
\r
418 /*****************************************************************************
\r
419 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
\r
420 * We don't show the menu directly here because we don't want the
\r
421 * caller to block for a too long time.
\r
422 *****************************************************************************/
\r
423 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
\r
424 vlc_value_t old_val, vlc_value_t new_val, void *param )
\r
426 #if !defined(MODULE_NAME_IS_basic_skins)
\r
427 Dialogs *p_dialogs = (Dialogs *)param;
\r
429 p_dialogs->ShowPopup();
\r
432 return VLC_SUCCESS;
\r