1 /*****************************************************************************
2 * events.c: Windows DirectX video output events handler
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble: This file contains the functions related to the creation of
27 * a window and the handling of its messages (events).
28 *****************************************************************************/
29 #include <errno.h> /* ENOMEM */
30 #include <stdlib.h> /* free() */
31 #include <ctype.h> /* tolower() */
32 #include <string.h> /* strerror() */
36 #include <vlc/input.h>
48 /*****************************************************************************
50 *****************************************************************************/
51 static int DirectXCreateWindow( vout_thread_t *p_vout );
52 static void DirectXCloseWindow ( vout_thread_t *p_vout );
53 static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
54 static long FAR PASCAL DirectXVideoEventProc( HWND, UINT, WPARAM, LPARAM );
56 static int Control( vout_thread_t *p_vout, int i_query, va_list args );
58 static void DirectXPopupMenu( event_thread_t *p_event, vlc_bool_t b_open )
60 playlist_t *p_playlist =
61 vlc_object_find( p_event, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
62 if( p_playlist != NULL )
66 var_Set( p_playlist, "intf-popupmenu", val );
67 vlc_object_release( p_playlist );
71 static int DirectXConvertKey( int i_key );
73 /*****************************************************************************
74 * DirectXEventThread: Create video window & handle its messages
75 *****************************************************************************
76 * This function creates a video window and then enters an infinite loop
77 * that handles the messages sent to that window.
78 * The main goal of this thread is to isolate the Win32 PeekMessage function
79 * because this one can block for a long time.
80 *****************************************************************************/
81 void DirectXEventThread( event_thread_t *p_event )
84 POINT old_mouse_pos = {0,0};
86 int i_width, i_height, i_x, i_y;
89 p_event->p_vout->pf_control = Control;
91 /* Create a window for the video */
92 /* Creating a window under Windows also initializes the thread's event
94 if( DirectXCreateWindow( p_event->p_vout ) )
96 msg_Err( p_event, "out of memory" );
97 p_event->b_dead = VLC_TRUE;
100 /* Signal the creation of the window */
101 vlc_thread_ready( p_event );
104 /* GetMessage will sleep if there's no message in the queue */
105 while( !p_event->b_die && ( p_event->p_vout->p_sys->hparent ||
106 GetMessage( &msg, p_event->p_vout->p_sys->hwnd, 0, 0 ) ) )
108 /* Check if we are asked to exit */
112 if( p_event->p_vout->p_sys->hparent )
114 /* Parent window was created in another thread so we can't
115 * access the window messages. */
116 msleep( INTF_IDLE_SLEEP );
120 switch( msg.message )
124 vout_PlacePicture( p_event->p_vout,
125 p_event->p_vout->p_sys->i_window_width,
126 p_event->p_vout->p_sys->i_window_height,
127 &i_x, &i_y, &i_width, &i_height );
129 if( msg.hwnd != p_event->p_vout->p_sys->hwnd )
135 if( i_width && i_height )
137 val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x )
138 * p_event->p_vout->render.i_width / i_width;
139 var_Set( p_event->p_vout, "mouse-x", val );
140 val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y )
141 * p_event->p_vout->render.i_height / i_height;
142 var_Set( p_event->p_vout, "mouse-y", val );
144 val.b_bool = VLC_TRUE;
145 var_Set( p_event->p_vout, "mouse-moved", val );
149 if( (abs(GET_X_LPARAM(msg.lParam) - old_mouse_pos.x) > 2 ||
150 (abs(GET_Y_LPARAM(msg.lParam) - old_mouse_pos.y)) > 2 ) )
152 GetCursorPos( &old_mouse_pos );
153 p_event->p_vout->p_sys->i_lastmoved = mdate();
155 if( p_event->p_vout->p_sys->b_cursor_hidden )
157 p_event->p_vout->p_sys->b_cursor_hidden = 0;
163 case WM_VLC_HIDE_MOUSE:
164 GetCursorPos( &old_mouse_pos );
169 var_Get( p_event->p_vout, "mouse-button-down", &val );
171 var_Set( p_event->p_vout, "mouse-button-down", val );
172 DirectXPopupMenu( p_event, VLC_FALSE );
176 var_Get( p_event->p_vout, "mouse-button-down", &val );
178 var_Set( p_event->p_vout, "mouse-button-down", val );
180 val.b_bool = VLC_TRUE;
181 var_Set( p_event->p_vout, "mouse-clicked", val );
184 case WM_LBUTTONDBLCLK:
185 p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
189 var_Get( p_event->p_vout, "mouse-button-down", &val );
191 var_Set( p_event->p_vout, "mouse-button-down", val );
192 DirectXPopupMenu( p_event, VLC_FALSE );
196 var_Get( p_event->p_vout, "mouse-button-down", &val );
198 var_Set( p_event->p_vout, "mouse-button-down", val );
202 var_Get( p_event->p_vout, "mouse-button-down", &val );
204 var_Set( p_event->p_vout, "mouse-button-down", val );
205 DirectXPopupMenu( p_event, VLC_FALSE );
209 var_Get( p_event->p_vout, "mouse-button-down", &val );
211 var_Set( p_event->p_vout, "mouse-button-down", val );
212 DirectXPopupMenu( p_event, VLC_TRUE );
217 /* The key events are first processed here and not translated
218 * into WM_CHAR events because we need to know the status of the
220 val.i_int = DirectXConvertKey( msg.wParam );
223 /* This appears to be a "normal" (ascii) key */
224 val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) );
229 if( GetKeyState(VK_CONTROL) & 0x8000 )
231 val.i_int |= KEY_MODIFIER_CTRL;
233 if( GetKeyState(VK_SHIFT) & 0x8000 )
235 val.i_int |= KEY_MODIFIER_SHIFT;
237 if( GetKeyState(VK_MENU) & 0x8000 )
239 val.i_int |= KEY_MODIFIER_ALT;
242 var_Set( p_event->p_vlc, "key-pressed", val );
247 if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
249 val.i_int = KEY_MOUSEWHEELUP;
253 val.i_int = KEY_MOUSEWHEELDOWN;
257 if( GetKeyState(VK_CONTROL) & 0x8000 )
259 val.i_int |= KEY_MODIFIER_CTRL;
261 if( GetKeyState(VK_SHIFT) & 0x8000 )
263 val.i_int |= KEY_MODIFIER_SHIFT;
265 if( GetKeyState(VK_MENU) & 0x8000 )
267 val.i_int |= KEY_MODIFIER_ALT;
270 var_Set( p_event->p_vlc, "key-pressed", val );
274 case WM_VLC_CHANGE_TEXT:
275 var_Get( p_event->p_vout, "video-title", &val );
277 if( !val.psz_string || !*val.psz_string ) /* Default video title */
279 if( p_event->p_vout->p_sys->b_using_overlay )
280 SetWindowText( p_event->p_vout->p_sys->hwnd,
281 VOUT_TITLE " (hardware YUV overlay DirectX output)" );
282 else if( p_event->p_vout->p_sys->b_hw_yuv )
283 SetWindowText( p_event->p_vout->p_sys->hwnd,
284 VOUT_TITLE " (hardware YUV DirectX output)" );
285 else SetWindowText( p_event->p_vout->p_sys->hwnd,
286 VOUT_TITLE " (software RGB DirectX output)" );
290 SetWindowText( p_event->p_vout->p_sys->hwnd, val.psz_string );
295 /* Messages we don't handle directly are dispatched to the
296 * window procedure */
297 TranslateMessage(&msg);
298 DispatchMessage(&msg);
303 } /* End Main loop */
305 /* Check for WM_QUIT if we created the window */
306 if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
308 msg_Warn( p_event, "WM_QUIT... should not happen!!" );
309 p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
312 msg_Dbg( p_event, "DirectXEventThread terminating" );
314 /* clear the changes formerly signaled */
315 p_event->p_vout->p_sys->i_changes = 0;
317 DirectXCloseWindow( p_event->p_vout );
321 /* following functions are local */
323 /*****************************************************************************
324 * DirectXCreateWindow: create a window for the video.
325 *****************************************************************************
326 * Before creating a direct draw surface, we need to create a window in which
327 * the video will be displayed. This window will also allow us to capture the
329 *****************************************************************************/
330 static int DirectXCreateWindow( vout_thread_t *p_vout )
336 msg_Dbg( p_vout, "DirectXCreateWindow" );
338 /* Get this module's instance */
339 hInstance = GetModuleHandle(NULL);
341 /* If an external window was specified, we'll draw in it. */
342 p_vout->p_sys->hparent = p_vout->p_sys->hwnd =
343 vout_RequestWindow( p_vout, &p_vout->p_sys->i_window_x,
344 &p_vout->p_sys->i_window_y,
345 &p_vout->p_sys->i_window_width,
346 &p_vout->p_sys->i_window_height );
348 if( p_vout->p_sys->hparent )
350 msg_Dbg( p_vout, "using external window %p\n", p_vout->p_sys->hwnd );
352 /* Set stuff in the window that we can not put directly in
353 * a class (see below). */
354 SetClassLong( p_vout->p_sys->hwnd,
355 GCL_STYLE, CS_DBLCLKS );
356 SetClassLong( p_vout->p_sys->hwnd,
357 GCL_HBRBACKGROUND, (LONG)GetStockObject(BLACK_BRUSH) );
358 SetClassLong( p_vout->p_sys->hwnd,
359 GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_ARROW) );
360 /* Store a p_vout pointer into the window local storage (for later
361 * use in DirectXEventProc). */
362 SetWindowLongPtr( p_vout->p_sys->hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );
364 p_vout->p_sys->pf_wndproc =
365 (WNDPROC)SetWindowLong( p_vout->p_sys->hwnd, GWLP_WNDPROC,
366 (LONG_PTR)DirectXEventProc );
368 /* Blam! Erase everything that might have been there. */
369 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
373 WNDCLASSEX wc; /* window class components */
374 HICON vlc_icon = NULL;
375 char vlc_path[MAX_PATH+1];
377 /* We create the window ourself, there is no previous window proc. */
378 p_vout->p_sys->pf_wndproc = NULL;
380 /* Get the Icon from the main app */
382 if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
384 vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
387 /* Fill in the window class structure */
388 wc.cbSize = sizeof(WNDCLASSEX);
389 wc.style = CS_DBLCLKS; /* style: dbl click */
390 wc.lpfnWndProc = (WNDPROC)DirectXEventProc; /* event handler */
391 wc.cbClsExtra = 0; /* no extra class data */
392 wc.cbWndExtra = 0; /* no extra window data */
393 wc.hInstance = hInstance; /* instance */
394 wc.hIcon = vlc_icon; /* load the vlc big icon */
395 wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* default cursor */
396 wc.hbrBackground = GetStockObject(BLACK_BRUSH); /* background color */
397 wc.lpszMenuName = NULL; /* no menu */
398 wc.lpszClassName = "VLC DirectX"; /* use a special class */
399 wc.hIconSm = vlc_icon; /* load the vlc small icon */
401 /* Register the window class */
402 if( !RegisterClassEx(&wc) )
408 DestroyIcon( vlc_icon );
411 /* Check why it failed. If it's because one already exists
412 * then fine, otherwise return with an error. */
413 if( !GetClassInfo( hInstance, "VLC DirectX", &wndclass ) )
415 msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED" );
420 /* When you create a window you give the dimensions you wish it to
421 * have. Unfortunatly these dimensions will include the borders and
422 * titlebar. We use the following function to find out the size of
423 * the window corresponding to the useable surface we want */
424 rect_window.top = 10;
425 rect_window.left = 10;
426 rect_window.right = rect_window.left + p_vout->p_sys->i_window_width;
427 rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;
428 AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
430 /* Create the window */
431 p_vout->p_sys->hwnd =
432 CreateWindow( "VLC DirectX", /* name of window class */
433 VOUT_TITLE " (DirectX Output)", /* window title bar text */
434 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE |
435 WS_CLIPCHILDREN, /* window style */
436 (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :
437 p_vout->p_sys->i_window_x, /* default X coordinate */
438 (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :
439 p_vout->p_sys->i_window_y, /* default Y coordinate */
440 rect_window.right - rect_window.left, /* window width */
441 rect_window.bottom - rect_window.top, /* window height */
442 NULL, /* no parent window */
443 NULL, /* no menu in this window */
444 hInstance, /* handle of this program instance */
445 (LPVOID)p_vout ); /* send p_vout to WM_CREATE */
447 if( !p_vout->p_sys->hwnd )
449 msg_Warn( p_vout, "DirectXCreateWindow create window FAILED" );
454 /* Now display the window */
455 ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
457 /* Create video sub-window. This sub window will always exactly match
458 * the size of the video, which allows us to use crazy overlay colorkeys
459 * without having them shown outside of the video area. */
460 SendMessage( p_vout->p_sys->hwnd, WM_VLC_CREATE_VIDEO_WIN, 0, 0 );
462 /* Append a "Always On Top" entry in the system menu */
463 hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
464 AppendMenu( hMenu, MF_SEPARATOR, 0, "" );
465 AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
466 IDM_TOGGLE_ON_TOP, "Always on &Top" );
471 /*****************************************************************************
472 * DirectXCloseWindow: close the window created by DirectXCreateWindow
473 *****************************************************************************
474 * This function returns all resources allocated by DirectXCreateWindow.
475 *****************************************************************************/
476 static void DirectXCloseWindow( vout_thread_t *p_vout )
478 msg_Dbg( p_vout, "DirectXCloseWindow" );
480 if( p_vout->p_sys->hwnd && !p_vout->p_sys->hparent )
482 DestroyWindow( p_vout->p_sys->hwnd );
484 else if( p_vout->p_sys->hparent )
486 /* Get rid of the video sub-window */
487 PostMessage( p_vout->p_sys->hvideownd, WM_VLC_DESTROY_VIDEO_WIN, 0, 0);
489 /* We don't want our windowproc to be called anymore */
490 SetWindowLongPtr( p_vout->p_sys->hwnd,
491 GWLP_WNDPROC, (LONG_PTR)p_vout->p_sys->pf_wndproc );
492 SetWindowLongPtr( p_vout->p_sys->hwnd, GWLP_USERDATA, 0 );
494 /* Blam! Erase everything that might have been there. */
495 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
497 vout_ReleaseWindow( p_vout, (void *)p_vout->p_sys->hparent );
500 p_vout->p_sys->hwnd = NULL;
502 /* We don't unregister the Window Class because it could lead to race
503 * conditions and it will be done anyway by the system when the app will
507 /*****************************************************************************
508 * DirectXUpdateRects: update clipping rectangles
509 *****************************************************************************
510 * This function is called when the window position or size are changed, and
511 * its job is to update the source and destination RECTs used to display the
513 *****************************************************************************/
514 void DirectXUpdateRects( vout_thread_t *p_vout, vlc_bool_t b_force )
516 #define rect_src p_vout->p_sys->rect_src
517 #define rect_src_clipped p_vout->p_sys->rect_src_clipped
518 #define rect_dest p_vout->p_sys->rect_dest
519 #define rect_dest_clipped p_vout->p_sys->rect_dest_clipped
521 int i_width, i_height, i_x, i_y;
526 /* Retrieve the window size */
527 GetClientRect( p_vout->p_sys->hwnd, &rect );
529 /* Retrieve the window position */
530 point.x = point.y = 0;
531 ClientToScreen( p_vout->p_sys->hwnd, &point );
533 /* If nothing changed, we can return */
535 && p_vout->p_sys->i_window_width == rect.right
536 && p_vout->p_sys->i_window_height == rect.bottom
537 && p_vout->p_sys->i_window_x == point.x
538 && p_vout->p_sys->i_window_y == point.y )
543 /* Update the window position and size */
544 p_vout->p_sys->i_window_x = point.x;
545 p_vout->p_sys->i_window_y = point.y;
546 p_vout->p_sys->i_window_width = rect.right;
547 p_vout->p_sys->i_window_height = rect.bottom;
549 vout_PlacePicture( p_vout, rect.right, rect.bottom,
550 &i_x, &i_y, &i_width, &i_height );
552 if( p_vout->p_sys->hvideownd )
553 SetWindowPos( p_vout->p_sys->hvideownd, HWND_TOP,
554 i_x, i_y, i_width, i_height, 0 );
556 /* Destination image position and dimensions */
557 rect_dest.left = point.x + i_x;
558 rect_dest.right = rect_dest.left + i_width;
559 rect_dest.top = point.y + i_y;
560 rect_dest.bottom = rect_dest.top + i_height;
562 /* Apply overlay hardware constraints */
563 if( p_vout->p_sys->b_using_overlay )
565 if( p_vout->p_sys->i_align_dest_boundary )
566 rect_dest.left = ( rect_dest.left +
567 p_vout->p_sys->i_align_dest_boundary / 2 ) &
568 ~p_vout->p_sys->i_align_dest_boundary;
570 if( p_vout->p_sys->i_align_dest_size )
571 rect_dest.right = (( rect_dest.right - rect_dest.left +
572 p_vout->p_sys->i_align_dest_size / 2 ) &
573 ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;
576 /* UpdateOverlay directdraw function doesn't automatically clip to the
577 * display size so we need to do it otherwise it will fail */
579 /* Clip the destination window */
580 if( !IntersectRect( &rect_dest_clipped, &rect_dest,
581 &p_vout->p_sys->rect_display ) )
583 SetRectEmpty( &rect_src_clipped );
588 msg_Dbg( p_vout, "DirectXUpdateRects image_dst_clipped coords:"
590 rect_dest_clipped.left, rect_dest_clipped.top,
591 rect_dest_clipped.right, rect_dest_clipped.bottom );
594 /* the 2 following lines are to fix a bug when clicking on the desktop */
595 if( (rect_dest_clipped.right - rect_dest_clipped.left)==0 ||
596 (rect_dest_clipped.bottom - rect_dest_clipped.top)==0 )
598 SetRectEmpty( &rect_src_clipped );
602 /* src image dimensions */
605 rect_src.right = p_vout->render.i_width;
606 rect_src.bottom = p_vout->render.i_height;
608 /* Clip the source image */
609 rect_src_clipped.left = (rect_dest_clipped.left - rect_dest.left) *
610 p_vout->render.i_width / (rect_dest.right - rect_dest.left);
611 rect_src_clipped.right = p_vout->render.i_width -
612 (rect_dest.right - rect_dest_clipped.right) * p_vout->render.i_width /
613 (rect_dest.right - rect_dest.left);
614 rect_src_clipped.top = (rect_dest_clipped.top - rect_dest.top) *
615 p_vout->render.i_height / (rect_dest.bottom - rect_dest.top);
616 rect_src_clipped.bottom = p_vout->render.i_height -
617 (rect_dest.bottom - rect_dest_clipped.bottom) * p_vout->render.i_height /
618 (rect_dest.bottom - rect_dest.top);
620 /* Apply overlay hardware constraints */
621 if( p_vout->p_sys->b_using_overlay )
623 if( p_vout->p_sys->i_align_src_boundary )
624 rect_src_clipped.left = ( rect_src_clipped.left +
625 p_vout->p_sys->i_align_src_boundary / 2 ) &
626 ~p_vout->p_sys->i_align_src_boundary;
628 if( p_vout->p_sys->i_align_src_size )
629 rect_src_clipped.right = (( rect_src_clipped.right -
630 rect_src_clipped.left +
631 p_vout->p_sys->i_align_src_size / 2 ) &
632 ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;
636 msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"
637 " coords: %i,%i,%i,%i",
638 rect_src_clipped.left, rect_src_clipped.top,
639 rect_src_clipped.right, rect_src_clipped.bottom );
642 /* The destination coordinates need to be relative to the current
643 * directdraw primary surface (display) */
644 rect_dest_clipped.left -= p_vout->p_sys->rect_display.left;
645 rect_dest_clipped.right -= p_vout->p_sys->rect_display.left;
646 rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;
647 rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;
649 /* Signal the change in size/position */
650 p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;
653 #undef rect_src_clipped
655 #undef rect_dest_clipped
658 /*****************************************************************************
659 * DirectXEventProc: This is the window event processing function.
660 *****************************************************************************
661 * On Windows, when you create a window you have to attach an event processing
662 * function to it. The aim of this function is to manage "Queued Messages" and
663 * "Nonqueued Messages".
664 * Queued Messages are those picked up and retransmitted by vout_Manage
665 * (using the GetMessage and DispatchMessage functions).
666 * Nonqueued Messages are those that Windows will send directly to this
667 * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...)
668 *****************************************************************************/
669 static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
670 WPARAM wParam, LPARAM lParam )
672 vout_thread_t *p_vout;
674 if( message == WM_CREATE )
676 /* Store p_vout for future use */
677 p_vout = (vout_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
678 SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );
682 p_vout = (vout_thread_t *)GetWindowLongPtr( hwnd, GWLP_USERDATA );
687 /* Hmmm mozilla does manage somehow to save the pointer to our
688 * windowproc and still calls it after the vout has been closed. */
689 return DefWindowProc(hwnd, message, wParam, lParam);
695 case WM_WINDOWPOSCHANGED:
696 DirectXUpdateRects( p_vout, VLC_TRUE );
699 /* the user wants to close the window */
702 playlist_t * p_playlist =
703 (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
705 if( p_playlist == NULL )
710 playlist_Stop( p_playlist );
711 vlc_object_release( p_playlist );
715 /* the window has been closed so shut down everything now */
717 msg_Dbg( p_vout, "WinProc WM_DESTROY" );
718 /* just destroy the window */
719 PostQuitMessage( 0 );
725 case SC_SCREENSAVE: /* catch the screensaver */
726 case SC_MONITORPOWER: /* catch the monitor turn-off */
727 msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND" );
728 return 0; /* this stops them from happening */
729 case IDM_TOGGLE_ON_TOP: /* toggle the "on top" status */
732 msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
734 /* Get the current value... */
735 if( var_Get( p_vout, "video-on-top", &val ) < 0 )
737 /* ...and change it */
738 val.b_bool = !val.b_bool;
739 var_Set( p_vout, "video-on-top", val );
746 case WM_VLC_CREATE_VIDEO_WIN:
747 /* Create video sub-window */
748 p_vout->p_sys->hvideownd =
749 CreateWindow( "STATIC", "", /* window class and title bar text */
750 WS_CHILD | WS_VISIBLE, /* window style */
751 CW_USEDEFAULT, CW_USEDEFAULT, /* default coordinates */
752 CW_USEDEFAULT, CW_USEDEFAULT,
753 hwnd, /* parent window */
754 NULL, GetModuleHandle(NULL), NULL );
756 if( !p_vout->p_sys->hvideownd )
758 msg_Warn( p_vout, "Can't create video sub-window" );
762 msg_Dbg( p_vout, "Created video sub-window" );
763 SetWindowLongPtr( p_vout->p_sys->hvideownd,
764 GWLP_WNDPROC, (LONG_PTR)DirectXVideoEventProc );
765 /* Store the previous window proc of _this_ window with the video
766 * window so we can use it in DirectXVideoEventProc to pass
767 * messages to the creator of _this_ window */
768 SetWindowLongPtr( p_vout->p_sys->hvideownd, GWLP_USERDATA,
769 (LONG_PTR)p_vout->p_sys->pf_wndproc );
776 /* We do not want to relay these messages to the parent window
777 * because we rely on the background color for the overlay. */
778 return DefWindowProc(hwnd, message, wParam, lParam);
782 //msg_Dbg( p_vout, "WinProc WM Default %i", message );
786 if( p_vout->p_sys->pf_wndproc )
790 /* Hmmm mozilla does manage somehow to save the pointer to our
791 * windowproc and will call us again whereby creating an
793 * We can detect this by resetting GWL_USERDATA before calling
794 * the parent's windowproc. */
795 SetWindowLongPtr( p_vout->p_sys->hwnd, GWLP_USERDATA, 0 );
797 /* Call next window proc in chain */
798 i_ret = CallWindowProc( p_vout->p_sys->pf_wndproc, hwnd, message,
801 SetWindowLongPtr( p_vout->p_sys->hwnd, GWLP_USERDATA,
807 /* Let windows handle the message */
808 return DefWindowProc(hwnd, message, wParam, lParam);
813 static long FAR PASCAL DirectXVideoEventProc( HWND hwnd, UINT message,
814 WPARAM wParam, LPARAM lParam )
816 WNDPROC pf_parentwndproc;
821 case WM_VLC_DESTROY_VIDEO_WIN:
822 /* Destroy video sub-window */
823 DestroyWindow( hwnd );
828 case WM_LBUTTONDBLCLK:
833 /* Translate mouse cursor position to parent window coordinates. */
834 pt.x = LOWORD( lParam );
835 pt.y = HIWORD( lParam );
836 MapWindowPoints( hwnd, GetParent( hwnd ), &pt, 1 );
837 lParam = MAKELPARAM( pt.x, pt.y );
843 /* Foward these to the original window proc of the parent so the
844 * creator of the window gets a chance to process them. If we created
845 * the parent window ourself DirectXEventThread will process these
846 * and they will never make it here.
847 * Note that we fake the hwnd to be our parent in order to prevent
848 * confusion in the creator's window proc. */
849 pf_parentwndproc = (WNDPROC)GetWindowLongPtr( hwnd, GWLP_USERDATA );
851 if( pf_parentwndproc )
856 pf_parentwndproc = (WNDPROC)GetWindowLongPtr( hwnd, GWLP_USERDATA);
858 p_backup = SetWindowLongPtr( GetParent( hwnd ), GWLP_USERDATA, 0 );
859 i_ret = CallWindowProc( pf_parentwndproc, GetParent( hwnd ),
860 message, wParam, lParam );
861 SetWindowLongPtr( GetParent( hwnd ), GWLP_USERDATA, p_backup );
868 return DefWindowProc(hwnd, message, wParam, lParam);
876 } dxkeys_to_vlckeys[] =
878 { VK_F1, KEY_F1 }, { VK_F2, KEY_F2 }, { VK_F3, KEY_F3 }, { VK_F4, KEY_F4 },
879 { VK_F5, KEY_F5 }, { VK_F6, KEY_F6 }, { VK_F7, KEY_F7 }, { VK_F8, KEY_F8 },
880 { VK_F9, KEY_F9 }, { VK_F10, KEY_F10 }, { VK_F11, KEY_F11 },
883 { VK_RETURN, KEY_ENTER },
884 { VK_SPACE, KEY_SPACE },
885 { VK_ESCAPE, KEY_ESC },
887 { VK_LEFT, KEY_LEFT },
888 { VK_RIGHT, KEY_RIGHT },
890 { VK_DOWN, KEY_DOWN },
892 { VK_HOME, KEY_HOME },
894 { VK_PRIOR, KEY_PAGEUP },
895 { VK_NEXT, KEY_PAGEDOWN },
904 static int DirectXConvertKey( int i_key )
908 for( i = 0; dxkeys_to_vlckeys[i].i_dxkey != 0; i++ )
910 if( dxkeys_to_vlckeys[i].i_dxkey == i_key )
912 return dxkeys_to_vlckeys[i].i_vlckey;
919 /*****************************************************************************
920 * Control: control facility for the vout
921 *****************************************************************************/
922 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
930 if( p_vout->p_sys->hparent )
931 return vout_ControlWindow( p_vout,
932 (void *)p_vout->p_sys->hparent, i_query, args );
934 f_arg = va_arg( args, double );
936 /* Update dimensions */
937 rect_window.top = rect_window.left = 0;
938 rect_window.right = p_vout->i_window_width * f_arg;
939 rect_window.bottom = p_vout->i_window_height * f_arg;
940 AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
942 SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
943 rect_window.right - rect_window.left,
944 rect_window.bottom - rect_window.top, SWP_NOMOVE );
952 msg_Dbg( p_vout, "control query not supported" );