]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/wince.cpp
Remove uneeded warining (and often impossible to send)
[vlc] / modules / gui / wince / wince.cpp
index e9826a1b97ffb7b46c59b5feab68e45b45bc1dad..68869333768e70f429f49ac4a370cc25787fd74c 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
  *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_interface.h>
+#include <vlc_input.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 +50,34 @@ 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  ( vlc_object_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_shortname( "WinCE" );
     set_description( (char *) _("WinCE interface module") );
-    set_capability( "interface", 200 );
+    set_capability( "interface", 100 );
     set_callbacks( Open, Close );
     add_shortcut( "wince" );
-    set_program( "wcevlc" );
+
+    set_category( CAT_INTERFACE );
+    set_subcategory( SUBCAT_INTERFACE_MAIN );
+    add_bool( "wince-embed", 1, NULL,
+              EMBED_TEXT, EMBED_LONGTEXT, false );
+
+    add_submodule();
+    set_description( N_("WinCE dialogs provider") );
+    set_capability( "dialogs provider", 10 );
+    set_callbacks( OpenDialogs, Close );
 vlc_module_end();
 
 HINSTANCE hInstance = 0;
@@ -59,21 +91,31 @@ 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;
 
-    // Allocate instance and initialize some members
-    p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
-    if( p_intf->p_sys == NULL )
+    // 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 )
     {
-        msg_Err( p_intf, "out of memory" );
+        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 )
+        return VLC_ENOMEM;
+
     // Suscribe to messages bank
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
 
@@ -84,6 +126,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,16 +137,46 @@ 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;
+    intf_sys_t    *p_sys = p_intf->p_sys;
+
+    if( p_sys->p_input )
+    {
+        vlc_object_release( 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->p_sys->p_input )
+    if( p_intf->pf_show_dialog )
     {
-        vlc_object_release( p_intf->p_sys->p_input );
+        /* 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
@@ -118,17 +191,159 @@ static void Close ( vlc_object_t *p_this )
  *****************************************************************************/
 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, "WinCE Dialogs Thread",
+                               MainLoop, 0, true ) )
+        {
+            msg_Err( p_intf, "cannot create WinCE Dialogs Thread" );
+            p_intf->pf_show_dialog = NULL;
+        }
+    }
+    else
+    {
+        int canc = vlc_savecancel();
+        /* The module is used in interface mode */
+        MainLoop( VLC_OBJECT(p_intf) );
+        vlc_restorecancel( canc );
+    }
+}
+
+static void* MainLoop( vlc_object_t * p_this )
+{
+    intf_thread_t *p_intf = (intf_thread_t*)p_this;
     MSG msg;
-    Interface *pInterface = new Interface();
+    Interface *intf = 0;
+    int canc = vlc_savecancel ();
+
+    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 );
 
     // 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
+    vlc_restorecancel (canc);
+    return NULL;
+}
+
+/*****************************************************************************
+ * 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 );
+    }
 }