]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/wince.cpp
Remove useless test before a delete.
[vlc] / modules / gui / wince / wince.cpp
index e9826a1b97ffb7b46c59b5feab68e45b45bc1dad..fce018176b2cfe17e258f56af1356217a435a285 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * wince.cpp: WinCE gui plugin for VLC
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $Id$
  *
  * Author: Gildas Bazin <gbazin@videolan.org>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
+
+#if defined( UNDER_CE ) && defined(__MINGW32__)
+/* This is a gross hack for the wince gcc cross-compiler */
+#define _off_t long
+#endif
 
 #include "wince.h"
 
+#include <objbase.h>
+
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
@@ -37,15 +48,31 @@ static int  Open   ( vlc_object_t * );
 static void Close  ( vlc_object_t * );
 static void Run    ( intf_thread_t * );
 
+static int  OpenDialogs( vlc_object_t * );
+
+static void MainLoop  ( intf_thread_t * );
+static void ShowDialog( intf_thread_t *, int, int, intf_dialog_args_t * );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+#define EMBED_TEXT N_("Embed video in interface")
+#define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
+    "of having it in a separate window.")
+
 vlc_module_begin();
     set_description( (char *) _("WinCE interface module") );
-    set_capability( "interface", 200 );
+    set_capability( "interface", 100 );
     set_callbacks( Open, Close );
     add_shortcut( "wince" );
-    set_program( "wcevlc" );
+
+    add_bool( "wince-embed", 1, NULL,
+              EMBED_TEXT, EMBED_LONGTEXT, VLC_FALSE );
+
+    add_submodule();
+    set_description( _("WinCE dialogs provider") );
+    set_capability( "dialogs provider", 10 );
+    set_callbacks( OpenDialogs, Close );
 vlc_module_end();
 
 HINSTANCE hInstance = 0;
@@ -59,13 +86,26 @@ DllMain( HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
 }
 #endif
 
+/* Global variables used by _TOMB() / _FROMB() */
+wchar_t pwsz_mbtow_wince[2048];
+char psz_wtomb_wince[2048];
+
 /*****************************************************************************
  * Open: initialize interface
  *****************************************************************************/
-static int Open ( vlc_object_t *p_this )
+static int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
+    // Check if the application is running.
+    // If it's running then focus its window and bail out.
+    HWND hwndMain = FindWindow( _T("VLC WinCE"), _T("VLC media player") );
+    if( hwndMain )
+    {
+        SetForegroundWindow( hwndMain );
+        return VLC_EGENERIC;
+    }
+
     // Allocate instance and initialize some members
     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
@@ -75,7 +115,7 @@ static int Open ( vlc_object_t *p_this )
     }
 
     // Suscribe to messages bank
-    p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
+    p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
 
     // Misc init
     p_intf->p_sys->p_audio_menu = NULL;
@@ -84,6 +124,7 @@ static int Open ( vlc_object_t *p_this )
     p_intf->p_sys->p_settings_menu = NULL;
 
     p_intf->pf_run = Run;
+    p_intf->pf_show_dialog = NULL;
 
     p_intf->p_sys->p_input = NULL;
     p_intf->p_sys->b_playing = 0;
@@ -94,10 +135,20 @@ static int Open ( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+static int OpenDialogs( vlc_object_t *p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+    int i_ret = Open( p_this );
+
+    p_intf->pf_show_dialog = ShowDialog;
+
+    return i_ret;
+}
+
 /*****************************************************************************
  * Close: destroy interface
  *****************************************************************************/
-static void Close ( vlc_object_t *p_this )
+static void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
@@ -106,6 +157,25 @@ static void Close ( vlc_object_t *p_this )
         vlc_object_release( p_intf->p_sys->p_input );
     }
 
+    MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
+    delete p_intf->p_sys->p_video_menu;
+    MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
+    delete p_intf->p_sys->p_audio_menu;
+    MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
+    delete p_intf->p_sys->p_settings_menu;
+    MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
+    delete p_intf->p_sys->p_navig_menu;
+
+    if( p_intf->pf_show_dialog )
+    {
+        /* We must destroy the dialogs thread */
+#if 0
+        wxCommandEvent event( wxEVT_DIALOG, INTF_DIALOG_EXIT );
+        p_intf->p_sys->p_wxwindow->AddPendingEvent( event );
+#endif
+        vlc_thread_join( p_intf );
+    }
+
     // Unsuscribe to messages bank
     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
 
@@ -117,18 +187,167 @@ static void Close ( vlc_object_t *p_this )
  * Run: main loop
  *****************************************************************************/
 static void Run( intf_thread_t *p_intf )
+{
+    if( p_intf->pf_show_dialog )
+    {
+        /* The module is used in dialog provider mode */
+
+        /* Create a new thread for the dialogs provider */
+        if( vlc_thread_create( p_intf, "Skins Dialogs Thread",
+                               MainLoop, 0, VLC_TRUE ) )
+        {
+            msg_Err( p_intf, "cannot create Skins Dialogs Thread" );
+            p_intf->pf_show_dialog = NULL;
+        }
+    }
+    else
+    {
+        /* The module is used in interface mode */
+        MainLoop( p_intf );
+    }
+}
+
+static void MainLoop( intf_thread_t *p_intf )
 {
     MSG msg;
-    Interface *pInterface = new Interface();
+    Interface *intf = 0;
+
+    if( !hInstance ) hInstance = GetModuleHandle(NULL);
 
-    if( !pInterface->InitInstance( hInstance, p_intf ) ) return;
+    // Register window class
+    WNDCLASS wc;
+    wc.style = CS_HREDRAW | CS_VREDRAW ;
+    wc.lpfnWndProc = (WNDPROC)CBaseWindow::BaseWndProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hIcon = NULL;
+    wc.hInstance = hInstance;
+    wc.hCursor = NULL;
+    wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = _T("VLC WinCE");
+    RegisterClass( &wc );
+
+#ifndef UNDER_CE
+    /* Initialize OLE/COM */
+    CoInitialize( 0 );
+#endif
+
+    if( !p_intf->pf_show_dialog )
+    {
+        /* The module is used in interface mode */
+        p_intf->p_sys->p_window = intf = new Interface( p_intf, 0, hInstance );
+
+        /* Create/Show the interface */
+        if( !intf->InitInstance() ) goto end;
+    }
+
+    /* Creates the dialogs provider */
+    p_intf->p_sys->p_window =
+        CreateDialogsProvider( p_intf, p_intf->pf_show_dialog ?
+                               NULL : p_intf->p_sys->p_window, hInstance );
+
+    p_intf->p_sys->pf_show_dialog = ShowDialog;
+
+    /* OK, initialization is over */
+    vlc_thread_ready( p_intf );
+
+    /* Check if we need to start playing */
+    if( !p_intf->pf_show_dialog && p_intf->b_play )
+    {
+        playlist_t *p_playlist =
+            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                           FIND_ANYWHERE );
+        if( p_playlist )
+        {
+            playlist_Play( p_playlist );
+            vlc_object_release( p_playlist );
+        }
+    }
 
     // Main message loop
-    int status;
-    while( ( status = GetMessage( &msg, NULL, 0, 0 ) ) != 0 )
+    while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
     {
-        if( status == -1 ) return;
         TranslateMessage( &msg );
         DispatchMessage( &msg );
     }
+
+ end:
+    delete intf;
+
+#ifndef UNDER_CE
+    /* Uninitialize OLE/COM */
+    CoUninitialize();
+#endif
+}
+
+/*****************************************************************************
+ * CBaseWindow Implementation
+ *****************************************************************************/
+LRESULT CALLBACK CBaseWindow::BaseWndProc( HWND hwnd, UINT msg, WPARAM wParam,
+                                           LPARAM lParam )
+{
+    CBaseWindow *p_obj;
+
+    // check to see if a copy of the 'this' pointer needs to be saved
+    if( msg == WM_CREATE )
+    {
+        p_obj = (CBaseWindow *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
+        SetWindowLong( hwnd, GWL_USERDATA,
+                       (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
+
+        p_obj->hWnd = hwnd;
+    }
+
+    if( msg == WM_INITDIALOG )
+    {
+        p_obj = (CBaseWindow *)lParam;
+        SetWindowLong( hwnd, GWL_USERDATA, lParam );
+        p_obj->hWnd = hwnd;
+    }
+
+    // Retrieve the pointer
+    p_obj = (CBaseWindow *)GetWindowLong( hwnd, GWL_USERDATA );
+
+    if( !p_obj ) return DefWindowProc( hwnd, msg, wParam, lParam );
+
+    // Filter message through child classes
+    return p_obj->WndProc( hwnd, msg, wParam, lParam );
+}
+
+int CBaseWindow::CreateDialogBox( HWND hwnd, CBaseWindow *p_obj )
+{
+    uint8_t p_buffer[sizeof(DLGTEMPLATE) + sizeof(WORD) * 4];
+    DLGTEMPLATE *p_dlg_template = (DLGTEMPLATE *)p_buffer;
+    memset( p_dlg_template, 0, sizeof(DLGTEMPLATE) + sizeof(WORD) * 4 );
+
+    // these values are arbitrary, they won't be used normally anyhow
+    p_dlg_template->x  = 0; p_dlg_template->y  = 0;
+    p_dlg_template->cx = 300; p_dlg_template->cy = 300;
+    p_dlg_template->style =
+        DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX;
+
+    return DialogBoxIndirectParam( GetModuleHandle(0), p_dlg_template, hwnd,
+                                   (DLGPROC)p_obj->BaseWndProc, (LPARAM)p_obj);
+}
+
+/*****************************************************************************
+ * ShowDialog
+ *****************************************************************************/
+static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
+                        intf_dialog_args_t *p_arg )
+{
+    SendMessage( p_intf->p_sys->p_window->GetHandle(), WM_CANCELMODE, 0, 0 );
+    if( i_dialog_event == INTF_DIALOG_POPUPMENU && i_arg == 0 ) return;
+
+    /* Hack to prevent popup events to be enqueued when
+     * one is already active */
+#if 0
+    if( i_dialog_event != INTF_DIALOG_POPUPMENU ||
+        !p_intf->p_sys->p_popup_menu )
+#endif
+    {
+        SendMessage( p_intf->p_sys->p_window->GetHandle(),
+                     WM_APP + i_dialog_event, (WPARAM)i_arg, (LPARAM)p_arg );
+    }
 }