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.3 2003/06/05 21:22:27 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
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
58 #else // BASIC_SKINS
\r
60 #include "../../wxwindows/wxwindows.h"
\r
61 #include "share/vlc32x32.xpm" // include the graphic icon
\r
63 #define ShowOpen_Event 0
\r
64 #define ShowOpenSkin_Event 1
\r
65 #define ShowMessages_Event 2
\r
66 #define ShowPrefs_Event 3
\r
67 #define ShowFileInfo_Event 4
\r
68 #define ShowPopup_Event 5
\r
69 #define ExitThread_Event 99
\r
71 //---------------------------------------------------------------------------
\r
72 // Local classes declarations.
\r
73 //---------------------------------------------------------------------------
\r
75 DEFINE_EVENT_TYPE(wxEVT_DIALOG)
\r
77 class Instance: public wxApp
\r
82 Instance( intf_thread_t *_p_intf, CallBackObjects *callback );
\r
84 Instance( intf_thread_t *_p_intf );
\r
91 intf_thread_t *p_intf;
\r
94 CallBackObjects *callbackobj;
\r
97 DECLARE_EVENT_TABLE();
\r
100 BEGIN_EVENT_TABLE(Instance, wxApp)
\r
101 EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)
\r
102 EVT_COMMAND(ShowOpenSkin_Event, wxEVT_DIALOG, Dialogs::OnShowOpenSkin)
\r
103 EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)
\r
104 EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)
\r
105 EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)
\r
106 EVT_COMMAND(ShowPopup_Event, wxEVT_DIALOG, Dialogs::OnShowPopup)
\r
107 EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)
\r
110 //---------------------------------------------------------------------------
\r
111 // Implementation of Instance class
\r
112 //---------------------------------------------------------------------------
\r
113 Instance::Instance( )
\r
118 Instance::Instance( intf_thread_t *_p_intf, CallBackObjects *callback )
\r
122 callbackobj = callback;
\r
125 Instance::Instance( intf_thread_t *_p_intf )
\r
132 IMPLEMENT_APP_NO_MAIN(Instance)
\r
134 bool Instance::OnInit()
\r
136 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
\r
139 // Set event callback. Yes, it's a big hack ;)
\r
140 gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
\r
143 // Create all the dialog boxes
\r
144 p_intf->p_sys->p_dialogs->OpenDlg =
\r
145 new OpenDialog( p_intf, NULL, FILE_ACCESS );
\r
146 p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );
\r
147 p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );
\r
148 p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );
\r
152 g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
\r
155 // OK, initialization is over, now the other thread can go on working...
\r
156 vlc_thread_ready( p_intf->p_sys->p_dialogs->p_thread );
\r
158 /* Register callback for the intf-popupmenu variable */
\r
159 playlist_t *p_playlist =
\r
160 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
\r
162 if( p_playlist != NULL )
\r
164 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
\r
165 p_intf->p_sys->p_dialogs );
\r
166 vlc_object_release( p_playlist );
\r
169 /* Intercept all menu events in our custom event handler */
\r
170 p_intf->p_sys->p_dialogs->OpenDlg->PushEventHandler(
\r
171 new MenuEvtHandler( p_intf, NULL ) );
\r
176 int Instance::OnExit()
\r
178 // Delete evertything
\r
179 delete p_intf->p_sys->p_dialogs->FileInfoDlg;
\r
180 delete p_intf->p_sys->p_dialogs->PrefsDlg;
\r
181 delete p_intf->p_sys->p_dialogs->MessagesDlg;
\r
182 delete p_intf->p_sys->p_dialogs->OpenDlg;
\r
183 delete p_intf->p_sys->p_icon;
\r
188 //---------------------------------------------------------------------------
\r
189 #if !defined(__BUILTIN__) && defined( WIN32 )
\r
190 HINSTANCE hInstance = 0;
\r
191 extern "C" BOOL WINAPI
\r
192 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
\r
194 hInstance = (HINSTANCE)hModule;
\r
199 //---------------------------------------------------------------------------
\r
201 // We create all wxWindows dialogs in a separate thread because we don't want
\r
202 // any interaction with our own message loop
\r
203 //---------------------------------------------------------------------------
\r
204 void SkinsDialogsThread( dialogs_thread_t *p_thread )
\r
206 #if !defined( WIN32 )
\r
207 static char *p_args[] = { "" };
\r
209 intf_thread_t *p_intf = p_thread->p_intf;
\r
211 /* Hack to pass the p_intf pointer to the new wxWindow Instance object */
\r
212 wxTheApp = new Instance( p_intf );
\r
214 #if defined( WIN32 )
\r
215 #if !defined(__BUILTIN__)
\r
216 wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );
\r
218 wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );
\r
221 wxEntry( 1, p_args );
\r
227 //---------------------------------------------------------------------------
\r
228 // Implementation of Dialogs class
\r
229 //---------------------------------------------------------------------------
\r
230 Dialogs::Dialogs( intf_thread_t *_p_intf )
\r
233 p_intf->p_sys->p_dialogs = this;
\r
234 b_popup_change = VLC_FALSE;
\r
236 p_thread = (dialogs_thread_t *)vlc_object_create( p_intf,
\r
237 sizeof(dialogs_thread_t) );
\r
238 p_thread->p_intf = p_intf;
\r
240 // Create a new thread for wxWindows
\r
241 if( vlc_thread_create( p_thread, "Skins Dialogs Thread",
\r
242 SkinsDialogsThread, 0, VLC_TRUE ) )
\r
245 msg_Err( p_intf, "cannot create SkinsDialogsThread" );
\r
249 Dialogs::~Dialogs()
\r
251 wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );
\r
252 event.SetClientData( this );
\r
254 wxTheApp->AddPendingEvent( event );
\r
256 vlc_thread_join( p_thread );
\r
259 void Dialogs::ShowOpen( bool b_play )
\r
261 wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );
\r
262 event.SetClientData( this );
\r
263 event.SetInt( b_play );
\r
265 wxTheApp->AddPendingEvent( event );
\r
268 void Dialogs::ShowOpenSkin()
\r
270 wxCommandEvent event( wxEVT_DIALOG, ShowOpenSkin_Event );
\r
271 event.SetClientData( this );
\r
273 wxTheApp->AddPendingEvent( event );
\r
276 void Dialogs::ShowMessages()
\r
278 wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );
\r
279 event.SetClientData( this );
\r
281 wxTheApp->AddPendingEvent( event );
\r
284 void Dialogs::ShowPrefs()
\r
286 wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );
\r
287 event.SetClientData( this );
\r
289 wxTheApp->AddPendingEvent( event );
\r
292 void Dialogs::ShowFileInfo()
\r
294 wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );
\r
295 event.SetClientData( this );
\r
297 wxTheApp->AddPendingEvent( event );
\r
300 void Dialogs::OnShowOpen( wxCommandEvent& event )
\r
302 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
303 bool b_play = event.GetInt() ? TRUE : FALSE;
\r
305 if( p_dialogs->OpenDlg->IsShown() ) return;
\r
307 if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )
\r
312 // Check if playlist is available
\r
313 playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;
\r
314 if( p_playlist == NULL )
\r
322 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
324 playlist_Add( p_playlist,
\r
325 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
326 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
\r
328 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
\r
333 for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )
\r
335 playlist_Add( p_playlist,
\r
336 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),
\r
337 PLAYLIST_APPEND, PLAYLIST_END );
\r
341 // Refresh interface !
\r
342 p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
\r
343 ->PostSynchroMessage();
\r
348 void Dialogs::OnShowOpenSkin( wxCommandEvent& event )
\r
350 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
351 intf_thread_t *p_intf = p_dialogs->p_intf;
\r
353 wxFileDialog dialog( NULL,
\r
354 wxU(_("Open a skin file")), wxT(""), wxT(""),
\r
355 wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
\r
356 "All files|*.*"), wxOPEN );
\r
358 if( dialog.ShowModal() == wxID_OK )
\r
360 p_intf->p_sys->p_new_theme_file =
\r
361 new char[strlen(dialog.GetPath().mb_str()) + 1];
\r
363 strcpy( p_intf->p_sys->p_new_theme_file,
\r
364 dialog.GetPath().mb_str() );
\r
366 // Tell vlc to change skin after hiding interface
\r
367 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
\r
371 void Dialogs::OnShowMessages( wxCommandEvent& event )
\r
373 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
374 p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );
\r
377 void Dialogs::OnShowPrefs( wxCommandEvent& event )
\r
379 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
380 p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );
\r
383 void Dialogs::OnShowFileInfo( wxCommandEvent& event )
\r
385 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
386 p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );
\r
389 void Dialogs::OnShowPopup( wxCommandEvent& event )
\r
391 Dialogs *p_dialogs = (Dialogs *)event.GetClientData();
\r
393 wxPoint mousepos = wxGetMousePosition();
\r
395 wxMouseEvent mouseevent = wxMouseEvent( wxEVT_RIGHT_UP );
\r
396 mouseevent.m_x = p_dialogs->OpenDlg->ScreenToClient(mousepos).x;
\r
397 mouseevent.m_y = p_dialogs->OpenDlg->ScreenToClient(mousepos).y;
\r
399 ::PopupMenu( p_dialogs->p_intf,
\r
400 p_dialogs->OpenDlg, mouseevent.GetPosition() );
\r
403 void Dialogs::OnExitThread( wxCommandEvent& event )
\r
405 wxTheApp->ExitMainLoop();
\r
407 #endif // BASIC_SKINS
\r
409 /*****************************************************************************
\r
410 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
\r
411 * We don't show the menu directly here because we don't want the
\r
412 * caller to block for a too long time.
\r
413 *****************************************************************************/
\r
414 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
\r
415 vlc_value_t old_val, vlc_value_t new_val, void *param )
\r
417 Dialogs *p_dialogs = (Dialogs *)param;
\r
419 #ifndef BASIC_SKINS
\r
420 wxCommandEvent event( wxEVT_DIALOG, ShowPopup_Event );
\r
421 event.SetClientData( p_dialogs );
\r
423 wxTheApp->AddPendingEvent( event );
\r
424 #endif // BASIC_SKINS
\r
426 return VLC_SUCCESS;
\r