]> git.sesse.net Git - vlc/blobdiff - modules/video_output/directx/events.c
For consistency, remove references to vlc from libvlc
[vlc] / modules / video_output / directx / events.c
index a844444cafb57faceed4bf31862424435d5caa1d..4122baa1833e59aaa770c03caf01f846271653c2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * events.c: Windows DirectX video output events handler
  *****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 
@@ -32,7 +32,7 @@
 #include <string.h>                                            /* strerror() */
 
 #ifndef _WIN32_WINNT
-#   define _WIN32_WINNT 0x0400
+#   define _WIN32_WINNT 0x0500
 #endif
 
 #include <vlc/vlc.h>
 #include <windowsx.h>
 #include <shellapi.h>
 
+#ifdef MODULE_NAME_IS_vout_directx
 #include <ddraw.h>
+#endif
+#ifdef MODULE_NAME_IS_direct3d
+#include <d3d9.h>
+#endif
+#ifdef MODULE_NAME_IS_glwin32
+#include <GL/gl.h>
+#endif
 
 #include "vlc_keys.h"
 #include "vout.h"
@@ -144,11 +152,13 @@ void E_(DirectXEventThread)( event_thread_t *p_event )
 
             if( i_width && i_height )
             {
-                val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x )
-                             * p_event->p_vout->render.i_width / i_width;
+                val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) *
+                    p_event->p_vout->fmt_in.i_visible_width / i_width +
+                    p_event->p_vout->fmt_in.i_x_offset;
                 var_Set( p_event->p_vout, "mouse-x", val );
-                val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y )
-                             * p_event->p_vout->render.i_height / i_height;
+                val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) *
+                    p_event->p_vout->fmt_in.i_visible_height / i_height +
+                    p_event->p_vout->fmt_in.i_y_offset;
                 var_Set( p_event->p_vout, "mouse-y", val );
 
                 val.b_bool = VLC_TRUE;
@@ -259,7 +269,7 @@ void E_(DirectXEventThread)( event_thread_t *p_event )
                     val.i_int |= KEY_MODIFIER_ALT;
                 }
 
-                var_Set( p_event->p_vlc, "key-pressed", val );
+                var_Set( p_event->p_libvlc, "key-pressed", val );
             }
             break;
 
@@ -287,34 +297,47 @@ void E_(DirectXEventThread)( event_thread_t *p_event )
                     val.i_int |= KEY_MODIFIER_ALT;
                 }
 
-                var_Set( p_event->p_vlc, "key-pressed", val );
+                var_Set( p_event->p_libvlc, "key-pressed", val );
             }
             break;
 
         case WM_VLC_CHANGE_TEXT:
             var_Get( p_event->p_vout, "video-title", &val );
-
             if( !val.psz_string || !*val.psz_string ) /* Default video title */
             {
+                if( val.psz_string ) free( val.psz_string );
+
 #ifdef MODULE_NAME_IS_glwin32
-                SetWindowText( p_event->p_vout->p_sys->hwnd,
-                    _T(VOUT_TITLE) _T(" (OpenGL output)") );
-#else
-                if( p_event->p_vout->p_sys->b_using_overlay )
-                    SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE)
-                        _T(" (hardware YUV overlay DirectX output)") );
-                else if( p_event->p_vout->p_sys->b_hw_yuv )
-                    SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE)
-                        _T(" (hardware YUV DirectX output)") );
-                else
-                    SetWindowText( p_event->p_vout->p_sys->hwnd, _T(VOUT_TITLE)
-                        _T(" (software RGB DirectX output)") );
+                val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );
+#endif
+#ifdef MODULE_NAME_IS_direct3d
+                val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );
+#endif
+#ifdef MODULE_NAME_IS_directx
+                if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string = 
+                strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );
+                else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string = 
+                strdup( VOUT_TITLE " (hardware YUV DirectX output)" );
+                else val.psz_string = 
+                strdup( VOUT_TITLE " (software RGB DirectX output)" );
 #endif
             }
-            else
+
+#ifdef UNICODE
             {
-                SetWindowText( p_event->p_vout->p_sys->hwnd, val.psz_string );
+                wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );
+                mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);
+                psz_title[strlen(val.psz_string)] = 0;
+                free( val.psz_string ); val.psz_string = (char *)psz_title;
             }
+#endif
+
+            SetWindowText( p_event->p_vout->p_sys->hwnd,
+                           (LPCTSTR)val.psz_string );
+            if( p_event->p_vout->p_sys->hfswnd )
+                SetWindowText( p_event->p_vout->p_sys->hfswnd,
+                               (LPCTSTR)val.psz_string );
+            free( val.psz_string );
             break;
 
         default:
@@ -361,7 +384,7 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     WNDCLASS   wc;                            /* window class components */
     HICON      vlc_icon = NULL;
     char       vlc_path[MAX_PATH+1];
-    int        i_style;
+    int        i_style, i_stylex;
 
     msg_Dbg( p_vout, "DirectXCreateWindow" );
 
@@ -438,25 +461,41 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     rect_window.left   = 10;
     rect_window.right  = rect_window.left + p_vout->p_sys->i_window_width;
     rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;
-    AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
 
-    i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
+    if( var_GetBool( p_vout, "video-deco" ) )
+    {
+        /* Open with window decoration */
+        AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
+        i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
+        i_stylex = 0;
+    }
+    else
+    {
+        /* No window decoration */
+        AdjustWindowRect( &rect_window, WS_POPUP, 0 );
+        i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;
+        i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?
+                      // It messes up the fullscreen window.
+    }
 
     if( p_vout->p_sys->hparent )
     {
         i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
+        i_stylex = 0;
     }
 
+    p_vout->p_sys->i_window_style = i_style;
+
     /* Create the window */
     p_vout->p_sys->hwnd =
-        CreateWindowEx( WS_EX_NOPARENTNOTIFY,
+        CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
                     _T("VLC DirectX"),               /* name of window class */
                     _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */
                     i_style,                                 /* window style */
                     (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :
-                        p_vout->p_sys->i_window_x,   /* default X coordinate */
+                        (UINT)p_vout->p_sys->i_window_x,   /* default X coordinate */
                     (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :
-                        p_vout->p_sys->i_window_y,   /* default Y coordinate */
+                        (UINT)p_vout->p_sys->i_window_y,   /* default Y coordinate */
                     rect_window.right - rect_window.left,    /* window width */
                     rect_window.bottom - rect_window.top,   /* window height */
                     p_vout->p_sys->hparent,                 /* parent window */
@@ -492,20 +531,33 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
                             NULL, NULL, hInstance, NULL );
     }
 
-    /* Now display the window */
-    ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
-
-    /* Create video sub-window. This sub window will always exactly match
-     * the size of the video, which allows us to use crazy overlay colorkeys
-     * without having them shown outside of the video area. */
-    SendMessage( p_vout->p_sys->hwnd, WM_VLC_CREATE_VIDEO_WIN, 0, 0 );
-
     /* Append a "Always On Top" entry in the system menu */
     hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
     AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
     AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
                        IDM_TOGGLE_ON_TOP, _T("Always on &Top") );
 
+    /* Create video sub-window. This sub window will always exactly match
+     * the size of the video, which allows us to use crazy overlay colorkeys
+     * without having them shown outside of the video area. */
+    p_vout->p_sys->hvideownd =
+       CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */
+               WS_CHILD | WS_VISIBLE,                   /* window style */
+               0, 0,
+               p_vout->render.i_width,                 /* default width */
+               p_vout->render.i_height,                /* default height */
+               p_vout->p_sys->hwnd,                    /* parent window */
+               NULL, hInstance,
+               (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
+
+    if( !p_vout->p_sys->hvideownd )
+       msg_Warn( p_vout, "can't create video sub-window" );
+    else
+       msg_Dbg( p_vout, "created video sub-window" );
+
+    /* Now display the window */
+    ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
+
     return VLC_SUCCESS;
 }
 
@@ -586,6 +638,7 @@ void E_(DirectXUpdateRects)( vout_thread_t *p_vout, vlc_bool_t b_force )
     rect_dest.top = point.y + i_y;
     rect_dest.bottom = rect_dest.top + i_height;
 
+#ifdef MODULE_NAME_IS_vout_directx
     /* Apply overlay hardware constraints */
     if( p_vout->p_sys->b_using_overlay )
     {
@@ -599,6 +652,7 @@ void E_(DirectXUpdateRects)( vout_thread_t *p_vout, vlc_bool_t b_force )
                 p_vout->p_sys->i_align_dest_size / 2 ) & 
                 ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;
     }
+#endif
 
     /* UpdateOverlay directdraw function doesn't automatically clip to the
      * display size so we need to do it otherwise it will fail */
@@ -633,17 +687,22 @@ void E_(DirectXUpdateRects)( vout_thread_t *p_vout, vlc_bool_t b_force )
     rect_src.bottom = p_vout->render.i_height;
 
     /* Clip the source image */
-    rect_src_clipped.left = (rect_dest_clipped.left - rect_dest.left) *
-      p_vout->render.i_width / (rect_dest.right - rect_dest.left);
-    rect_src_clipped.right = p_vout->render.i_width -
-      (rect_dest.right - rect_dest_clipped.right) * p_vout->render.i_width /
-      (rect_dest.right - rect_dest.left);
-    rect_src_clipped.top = (rect_dest_clipped.top - rect_dest.top) *
-      p_vout->render.i_height / (rect_dest.bottom - rect_dest.top);
-    rect_src_clipped.bottom = p_vout->render.i_height -
-      (rect_dest.bottom - rect_dest_clipped.bottom) * p_vout->render.i_height /
-      (rect_dest.bottom - rect_dest.top);
-
+    rect_src_clipped.left = p_vout->fmt_out.i_x_offset +
+      (rect_dest_clipped.left - rect_dest.left) *
+      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
+    rect_src_clipped.right = p_vout->fmt_out.i_x_offset +
+      p_vout->fmt_out.i_visible_width -
+      (rect_dest.right - rect_dest_clipped.right) *
+      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
+    rect_src_clipped.top = p_vout->fmt_out.i_y_offset +
+      (rect_dest_clipped.top - rect_dest.top) *
+      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
+    rect_src_clipped.bottom = p_vout->fmt_out.i_y_offset +
+      p_vout->fmt_out.i_visible_height -
+      (rect_dest.bottom - rect_dest_clipped.bottom) *
+      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
+
+#ifdef MODULE_NAME_IS_vout_directx
     /* Apply overlay hardware constraints */
     if( p_vout->p_sys->b_using_overlay )
     {
@@ -658,6 +717,7 @@ void E_(DirectXUpdateRects)( vout_thread_t *p_vout, vlc_bool_t b_force )
                 p_vout->p_sys->i_align_src_size / 2 ) & 
                 ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;
     }
+#endif
 
 #if 0
     msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"
@@ -673,8 +733,10 @@ void E_(DirectXUpdateRects)( vout_thread_t *p_vout, vlc_bool_t b_force )
     rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;
     rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;
 
+#ifdef MODULE_NAME_IS_vout_directx
     if( p_vout->p_sys->b_using_overlay )
         E_(DirectXUpdateOverlay)( p_vout );
+#endif
 
     /* Signal the change in size/position */
     p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;
@@ -714,7 +776,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
 
     /* Catch the screensaver and the monitor turn-off */
     if( message == WM_SYSCOMMAND &&
-        ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER ) )
+        ( (wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER ) )
     {
         //if( p_vout ) msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND screensaver" );
         return 0; /* this stops them from happening */
@@ -777,23 +839,6 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
         }
         break;
 
-    case WM_VLC_CREATE_VIDEO_WIN:
-        /* Create video sub-window */
-        p_vout->p_sys->hvideownd =
-            CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */
-                    WS_CHILD | WS_VISIBLE,                   /* window style */
-                    CW_USEDEFAULT, CW_USEDEFAULT,     /* default coordinates */
-                    CW_USEDEFAULT, CW_USEDEFAULT,
-                    hwnd,                                   /* parent window */
-                    NULL, GetModuleHandle(NULL),
-                    (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
-
-        if( !p_vout->p_sys->hvideownd )
-            msg_Warn( p_vout, "Can't create video sub-window" );
-        else
-            msg_Dbg( p_vout, "Created video sub-window" );
-        break;
-
     case WM_PAINT:
     case WM_NCPAINT:
     case WM_ERASEBKGND:
@@ -837,10 +882,28 @@ static struct
     { VK_PRIOR, KEY_PAGEUP },
     { VK_NEXT, KEY_PAGEDOWN },
 
+    { VK_INSERT, KEY_INSERT },
+    { VK_DELETE, KEY_DELETE },
+
     { VK_CONTROL, 0 },
     { VK_SHIFT, 0 },
     { VK_MENU, 0 },
 
+    { VK_BROWSER_BACK, KEY_BROWSER_BACK },
+    { VK_BROWSER_FORWARD, KEY_BROWSER_FORWARD },
+    { VK_BROWSER_REFRESH, KEY_BROWSER_REFRESH },
+    { VK_BROWSER_STOP, KEY_BROWSER_STOP },
+    { VK_BROWSER_SEARCH, KEY_BROWSER_SEARCH },
+    { VK_BROWSER_FAVORITES, KEY_BROWSER_FAVORITES },
+    { VK_BROWSER_HOME, KEY_BROWSER_HOME },
+    { VK_VOLUME_MUTE, KEY_VOLUME_MUTE },
+    { VK_VOLUME_DOWN, KEY_VOLUME_DOWN },
+    { VK_VOLUME_UP, KEY_VOLUME_UP },
+    { VK_MEDIA_NEXT_TRACK, KEY_MEDIA_NEXT_TRACK },
+    { VK_MEDIA_PREV_TRACK, KEY_MEDIA_PREV_TRACK },
+    { VK_MEDIA_STOP, KEY_MEDIA_STOP },
+    { VK_MEDIA_PLAY_PAUSE, KEY_MEDIA_PLAY_PAUSE },
+
     { 0, 0 }
 };
 
@@ -864,24 +927,38 @@ static int DirectXConvertKey( int i_key )
  *****************************************************************************/
 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 {
-    double f_arg;
+    unsigned int *pi_width, *pi_height;
     RECT rect_window;
     POINT point;
 
     switch( i_query )
     {
-    case VOUT_SET_ZOOM:
+    case VOUT_GET_SIZE:
         if( p_vout->p_sys->hparent )
             return vout_ControlWindow( p_vout,
                     (void *)p_vout->p_sys->hparent, i_query, args );
 
-        f_arg = va_arg( args, double );
+        pi_width  = va_arg( args, unsigned int * );
+        pi_height = va_arg( args, unsigned int * );
+
+        GetClientRect( p_vout->p_sys->hwnd, &rect_window );
+
+        *pi_width  = rect_window.right - rect_window.left;
+        *pi_height = rect_window.bottom - rect_window.top;
+        return VLC_SUCCESS;
+
+    case VOUT_SET_SIZE:
+        if( p_vout->p_sys->hparent )
+            return vout_ControlWindow( p_vout,
+                    (void *)p_vout->p_sys->hparent, i_query, args );
 
         /* Update dimensions */
         rect_window.top = rect_window.left = 0;
-        rect_window.right  = p_vout->i_window_width * f_arg;
-        rect_window.bottom = p_vout->i_window_height * f_arg;
-        AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
+        rect_window.right  = va_arg( args, unsigned int );
+        rect_window.bottom = va_arg( args, unsigned int );
+        if( !rect_window.right ) rect_window.right = p_vout->i_window_width;
+        if( !rect_window.bottom ) rect_window.bottom = p_vout->i_window_height;
+        AdjustWindowRect( &rect_window, p_vout->p_sys->i_window_style, 0 );
 
         SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
                       rect_window.right - rect_window.left,
@@ -901,10 +978,13 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
         point.x = point.y = 0;
         ClientToScreen( p_vout->p_sys->hwnd, &point );
 
-        SetParent( p_vout->p_sys->hwnd, GetDesktopWindow() );
+        SetParent( p_vout->p_sys->hwnd, 0 );
+        p_vout->p_sys->i_window_style =
+            WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW | WS_SIZEBOX;
         SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
-                       WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW |
-                       WS_SIZEBOX | (i_query == VOUT_CLOSE ? 0 : WS_VISIBLE) );
+                       p_vout->p_sys->i_window_style |
+                       (i_query == VOUT_CLOSE ? 0 : WS_VISIBLE) );
+        SetWindowLong( p_vout->p_sys->hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW );
         SetWindowPos( p_vout->p_sys->hwnd, 0, point.x, point.y, 0, 0,
                       SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED );