[vlc-devel] [PATCH 2/4] npapi win32: added window proc replacing for browser drawable window.

Sergey Radionov rsatom at gmail.com
Fri Dec 30 11:46:34 CET 2011


some browsers (mainly opera) have not good realization of NPApi,
and we will need track some events via native window messages,
rather than via NPP_SetWindow.
---
 npapi/vlcplugin_win.cpp |   26 +++++++++++++++++++++++++-
 npapi/vlcplugin_win.h   |    2 ++
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/npapi/vlcplugin_win.cpp b/npapi/vlcplugin_win.cpp
index 745cfec..13322d2 100644
--- a/npapi/vlcplugin_win.cpp
+++ b/npapi/vlcplugin_win.cpp
@@ -50,8 +50,17 @@ BOOL WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
 };
 
 
+LRESULT CALLBACK VlcPluginWin::NPWndProcR( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
+{
+    VlcPluginWin *p_plugin = reinterpret_cast<VlcPluginWin *>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
+
+    /* delegate to default handler */
+    return CallWindowProc( p_plugin->_NPWndProc, p_hwnd,
+                           i_msg, wpar, lpar );
+}
+
 VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
-    VlcPluginBase(instance, mode),
+    VlcPluginBase(instance, mode), _NPWndProc(0),
     _WindowsManager(DllGetModule())
 {
 }
@@ -108,6 +117,12 @@ bool VlcPluginWin::create_windows()
     SetWindowLongPtr(drawable, GWLP_USERDATA,
                      (LONG_PTR)this);
 
+    /* install our WNDPROC */
+    _NPWndProc =
+        (WNDPROC) SetWindowLongPtr( drawable,
+                                    GWLP_WNDPROC,
+                                    (LONG_PTR)NPWndProcR );
+
     /* change window style to our liking */
     LONG style = GetWindowLong(drawable, GWL_STYLE);
     style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
@@ -133,6 +148,15 @@ bool VlcPluginWin::resize_windows()
 bool VlcPluginWin::destroy_windows()
 {
     _WindowsManager.DestroyWindows();
+
+    HWND hWnd = (HWND)npwindow.window;
+    if( hWnd && _NPWndProc){
+        /* reset WNDPROC */
+        SetWindowLongPtr( hWnd, GWLP_WNDPROC, (LONG_PTR)_NPWndProc );
+    }
+    _NPWndProc = 0;
+    npwindow.window = 0;
+
     return true;
 }
 
diff --git a/npapi/vlcplugin_win.h b/npapi/vlcplugin_win.h
index bbc66c9..7415bed 100644
--- a/npapi/vlcplugin_win.h
+++ b/npapi/vlcplugin_win.h
@@ -63,8 +63,10 @@ protected:
     virtual void on_media_player_release();
 
 private:
+    static LRESULT CALLBACK NPWndProcR( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
     void set_player_window(){};
 
+    WNDPROC _NPWndProc;
     VLCWindowsManager _WindowsManager;
 };
 
-- 
1.7.7.1.msysgit.0




More information about the vlc-devel mailing list