33 #include <nsIThread.h>
34 #include <nsThreadUtils.h>
46 static PRLogModuleInfo* gGStreamerPlatformWin32 =
47 PR_NewLogModule(
"sbGStreamerPlatformWin32");
50 if (gGStreamerPlatformWin32) \
51 PR_LOG(gGStreamerPlatformWin32, PR_LOG_WARNING, args)
54 if (gGStreamerPlatformWin32) \
55 PR_LOG(gGStreamerPlatformWin32, PR_LOG_DEBUG, args)
65 #define SB_VIDEOWINDOW_CLASSNAME L"SBGStreamerVideoWindow"
67 #define CURSOR_HIDE_ID 1 //timer id
68 #define CURSOR_HIDE_DELAY 3000 //delay in milliseconds
74 #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
77 #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
81 Win32PlatformInterface::VideoWindowProc(HWND hWnd, UINT
message,
82 WPARAM wParam, LPARAM lParam)
89 nsCOMPtr<nsIDOMKeyEvent> keyEvent;
91 if(NS_SUCCEEDED(rv)) {
92 PRBool shiftKeyState = HIBYTE(GetKeyState(VK_SHIFT)) > 0;
93 PRBool ctrlKeyState = HIBYTE(GetKeyState(VK_CONTROL)) > 0;
94 PRBool altKeyState = HIBYTE(GetKeyState(VK_MENU)) > 0;
95 PRBool winKeyStateL = HIBYTE(GetKeyState(VK_LWIN)) > 0;
96 PRBool winKeyStateR = HIBYTE(GetKeyState(VK_RWIN)) > 0;
99 PRInt32 charCode = LOWORD(MapVirtualKey(wParam, MAPVK_VK_TO_CHAR));
101 rv = keyEvent->InitKeyEvent(NS_LITERAL_STRING(
"keypress"),
108 winKeyStateL || winKeyStateR,
111 if(NS_SUCCEEDED(rv)) {
112 nsCOMPtr<nsIDOMEvent>
event(do_QueryInterface(keyEvent));
121 case WM_LBUTTONDOWN: {
122 nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
124 if(NS_SUCCEEDED(rv)) {
125 PRBool shiftKeyState = HIBYTE(GetKeyState(VK_SHIFT)) > 0;
126 PRBool ctrlKeyState = HIBYTE(GetKeyState(VK_CONTROL)) > 0;
127 PRBool altKeyState = HIBYTE(GetKeyState(VK_MENU)) > 0;
128 PRBool winKeyStateL = HIBYTE(GetKeyState(VK_LWIN)) > 0;
129 PRBool winKeyStateR = HIBYTE(GetKeyState(VK_RWIN)) > 0;
138 BOOL success = ClientToScreen(hWnd, &point);
139 NS_WARN_IF_FALSE(success,
140 "Failed to convert coordinates, popup menu will be positioned wrong");
142 rv = mouseEvent->InitMouseEvent(NS_LITERAL_STRING(
"click"),
154 winKeyStateL || winKeyStateR,
157 if(NS_SUCCEEDED(rv)) {
158 nsCOMPtr<nsIDOMEvent>
event(do_QueryInterface(mouseEvent));
168 case WM_CONTEXTMENU: {
169 nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
171 if(NS_SUCCEEDED(rv)) {
172 PRBool shiftKeyState = HIBYTE(GetKeyState(VK_SHIFT)) > 0;
173 PRBool ctrlKeyState = HIBYTE(GetKeyState(VK_CONTROL)) > 0;
174 PRBool altKeyState = HIBYTE(GetKeyState(VK_MENU)) > 0;
175 PRBool winKeyStateL = HIBYTE(GetKeyState(VK_LWIN)) > 0;
176 PRBool winKeyStateR = HIBYTE(GetKeyState(VK_RWIN)) > 0;
181 PRInt32 clientX = screenX;
182 PRInt32 clientY = screenY;
185 BOOL success = FALSE;
187 if(message == WM_RBUTTONUP) {
191 success = ClientToScreen(hWnd, &point);
200 success = ScreenToClient(hWnd, &point);
203 NS_WARN_IF_FALSE(success,
204 "Failed to convert coordinates, popup menu will be positioned wrong");
206 rv = mouseEvent->InitMouseEvent(NS_LITERAL_STRING(
"contextmenu"),
218 winKeyStateL || winKeyStateR,
221 if(NS_SUCCEEDED(rv)) {
222 nsCOMPtr<nsIDOMEvent>
event(do_QueryInterface(mouseEvent));
235 if(platform->HasMouseMoved(clientX, clientY)) {
242 TRACKMOUSEEVENT tme = {0};
243 tme.cbSize =
sizeof(TRACKMOUSEEVENT);
244 tme.dwFlags = TME_LEAVE;
245 tme.hwndTrack = hWnd;
246 tme.dwHoverTime = HOVER_DEFAULT;
251 ::TrackMouseEvent(&tme);
253 if(!platform->mCursorShowing) {
255 platform->mCursorShowing = PR_TRUE;
260 nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
262 if(NS_SUCCEEDED(rv)) {
263 PRBool shiftKeyState = HIBYTE(GetKeyState(VK_SHIFT)) > 0;
264 PRBool ctrlKeyState = HIBYTE(GetKeyState(VK_CONTROL)) > 0;
265 PRBool altKeyState = HIBYTE(GetKeyState(VK_MENU)) > 0;
266 PRBool winKeyStateL = HIBYTE(GetKeyState(VK_LWIN)) > 0;
267 PRBool winKeyStateR = HIBYTE(GetKeyState(VK_RWIN)) > 0;
273 BOOL success = ClientToScreen(hWnd, &point);
274 NS_WARN_IF_FALSE(success,
275 "Failed to convert coords, mousemove will have wrong screen coords");
277 rv = mouseEvent->InitMouseEvent(NS_LITERAL_STRING(
"mousemove"),
289 winKeyStateL || winKeyStateR,
292 if(NS_SUCCEEDED(rv)) {
293 nsCOMPtr<nsIDOMEvent>
event(do_QueryInterface(mouseEvent));
303 case WM_MOUSELEAVE: {
304 if(!platform->mCursorShowing) {
306 platform->mCursorShowing = TRUE;
315 if(platform->mCursorShowing) {
317 platform->mCursorShowing = PR_FALSE;
328 return DefWindowProc(hWnd, message, wParam, lParam);
334 , mFullscreenWindow(NULL)
335 , mParentWindow(NULL)
336 , mCursorShowing(PR_TRUE)
349 NS_ENSURE_SUCCESS(rv, rv);
352 mParentWindow = (HWND)aWidget->GetNativeData(NS_NATIVE_WIDGET);
353 NS_ENSURE_TRUE(mParentWindow != NULL, NS_ERROR_FAILURE);
357 HWND actualParent = SelectParentWindow(mParentWindow);
361 ::ZeroMemory(&WndClass,
sizeof (WNDCLASS));
363 WndClass.style = CS_HREDRAW | CS_VREDRAW;
364 WndClass.hInstance = GetModuleHandle(NULL);
366 WndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
367 WndClass.cbClsExtra = 0;
368 WndClass.cbWndExtra = 0;
369 WndClass.lpfnWndProc = VideoWindowProc;
370 WndClass.hCursor = ::LoadCursor(NULL, IDC_ARROW);
372 ::RegisterClass(&WndClass);
374 mWindow = ::CreateWindowEx(
377 L
"Songbird GStreamer Video Window",
378 WS_CHILD | WS_CLIPCHILDREN,
386 ::SetWindowLongPtr(mWindow, GWLP_USERDATA, (
LONG)
this);
389 ::ShowWindow(mWindow, SW_SHOW);
393 ::ShowWindow(mWindow, SW_HIDE);
394 ::SetParent(mWindow, NULL);
396 ::DestroyWindow(mWindow);
399 mParentWindow = NULL;
417 ::DestroyWindow(mWindow);
424 NS_ASSERTION(mFullscreenWindow == NULL,
"Fullscreen window is not null");
429 monitor = ::MonitorFromWindow(mWindow, MONITOR_DEFAULTTONEAREST);
430 info.cbSize =
sizeof (MONITORINFO);
431 ::GetMonitorInfo(monitor, &info);
433 mFullscreenWindow = ::CreateWindowEx(
437 L
"Songbird Fullscreen Video Window",
439 info.rcMonitor.left, info.rcMonitor.top,
440 abs(info.rcMonitor.right - info.rcMonitor.left),
441 abs(info.rcMonitor.bottom - info.rcMonitor.top),
442 NULL, NULL, NULL, NULL);
444 ::SetWindowLongPtr(mFullscreenWindow, GWLP_USERDATA, (
LONG)
this);
446 ::SetParent(mWindow, mFullscreenWindow);
447 ::ShowWindow(mFullscreenWindow, SW_SHOWMAXIMIZED);
457 abs(info.rcMonitor.right - info.rcMonitor.left),
458 abs(info.rcMonitor.bottom - info.rcMonitor.top));
465 NS_ASSERTION(mFullscreenWindow,
"Fullscreen window is null");
468 ::ShowWindow(mWindow, SW_HIDE);
472 HWND actualParent = SelectParentWindow(mParentWindow);
475 ::SetParent(mWindow, actualParent);
479 ::ShowWindow(mWindow, SW_SHOW);
481 ::DestroyWindow(mFullscreenWindow);
482 mFullscreenWindow = NULL;
484 if(!mCursorShowing) {
486 mCursorShowing = TRUE;
498 ::SetWindowPos(mWindow, NULL, x, y, width, height,
499 SWP_NOZORDER | SWP_ASYNCWINDOWPOS);
515 mVideoSink = ::gst_element_factory_make(
"dshowvideosink", NULL);
517 mVideoSink = ::gst_element_factory_make(
"autovideosink", NULL);
537 mAudioSink = gst_element_factory_make(
"directsoundsink",
"audio-sink");
542 mAudioSink = gst_element_factory_make(
"autoaudiosink",
"audio-sink");
565 nsCOMPtr<nsIThread> mainThread;
566 rv = NS_GetMainThread(getter_AddRefs(mainThread));
567 NS_ENSURE_SUCCESS(rv, );
569 nsCOMPtr<nsIRunnable> runnable =
574 rv = mainThread->Dispatch(runnable, NS_DISPATCH_SYNC);
575 NS_ENSURE_SUCCESS(rv, );
579 gst_x_overlay_set_xwindow_id(aXOverlay, (glong)mWindow);
581 LOG((
"Set xoverlay %p to HWND %x\n", aXOverlay, mWindow));
586 Win32PlatformInterface::SelectParentWindow(HWND hWnd)
593 HWND firstChildWnd = ::GetWindow(hWnd, GW_CHILD);
595 if(firstChildWnd != NULL) {
596 retWnd = ::GetWindow(firstChildWnd, GW_HWNDLAST);
607 Win32PlatformInterface::HasMouseMoved(PRInt32 aX, PRInt32 aY)
609 PRBool hasMoved = PR_FALSE;
611 if(mLastMouseX != aX) {
616 if(mLastMouseY != aY) {
Songbird Variant Utility Definitions.