From 4a3c6a381405ebfd0e3c188451f7308bddb7d621 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Tue, 26 Mar 2002 23:43:49 +0000 Subject: [PATCH] [not part of build] make scriptable plugin work on XP_MAC. --- .../plugin/samples/4x-scriptable/npp_gate.cpp | 4 +++ .../plugin/samples/4x-scriptable/plugin.cpp | 30 ++++++++++++++++++- modules/plugin/samples/4x-scriptable/plugin.h | 4 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/plugin/samples/4x-scriptable/npp_gate.cpp b/modules/plugin/samples/4x-scriptable/npp_gate.cpp index f887142f0156..056a623b49ef 100644 --- a/modules/plugin/samples/4x-scriptable/npp_gate.cpp +++ b/modules/plugin/samples/4x-scriptable/npp_gate.cpp @@ -252,6 +252,10 @@ int16 NPP_HandleEvent(NPP instance, void* event) return 0; int16 rv = 0; + CPlugin * pPlugin = (CPlugin *)instance->pdata; + if (pPlugin) + rv = pPlugin->handleEvent(event); + return rv; } diff --git a/modules/plugin/samples/4x-scriptable/plugin.cpp b/modules/plugin/samples/4x-scriptable/plugin.cpp index d321635ceca8..88dede711fb4 100644 --- a/modules/plugin/samples/4x-scriptable/plugin.cpp +++ b/modules/plugin/samples/4x-scriptable/plugin.cpp @@ -44,6 +44,10 @@ #include #endif +#ifdef XP_MAC +#include +#endif + #include "plugin.h" CPlugin::CPlugin(NPP pNPInstance) : @@ -56,7 +60,8 @@ CPlugin::CPlugin(NPP pNPInstance) : m_hWnd = NULL; #endif - m_String[0] = '\0'; + const char *ua = NPN_UserAgent(m_pNPInstance); + strcpy(m_String, ua); } CPlugin::~CPlugin() @@ -88,6 +93,8 @@ NPBool CPlugin::init(NPWindow* pNPWindow) SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this); #endif + m_Window = pNPWindow; + m_bInitialized = TRUE; return TRUE; } @@ -108,6 +115,21 @@ NPBool CPlugin::isInitialized() return m_bInitialized; } +int16 CPlugin::handleEvent(void* event) +{ +#ifdef XP_MAC + NPEvent* ev = (NPEvent*)event; + if (m_Window) { + Rect box = { m_Window->y, m_Window->x, + m_Window->y + m_Window->height, m_Window->x + m_Window->width }; + if (ev->what == updateEvt) { + ::TETextBox(m_String, strlen(m_String), &box, teJustCenter); + } + } +#endif + return 0; +} + // this will force to draw a version string in the plugin window void CPlugin::showVersion() { @@ -118,6 +140,12 @@ void CPlugin::showVersion() InvalidateRect(m_hWnd, NULL, TRUE); UpdateWindow(m_hWnd); #endif + + if (m_Window) { + NPRect r = { m_Window->y, m_Window->x, + m_Window->y + m_Window->height, m_Window->x + m_Window->width }; + NPN_InvalidateRect(m_pNPInstance, &r); + } } // this will clean the plugin window diff --git a/modules/plugin/samples/4x-scriptable/plugin.h b/modules/plugin/samples/4x-scriptable/plugin.h index 6c42c16b45fe..4ea5dc017c89 100644 --- a/modules/plugin/samples/4x-scriptable/plugin.h +++ b/modules/plugin/samples/4x-scriptable/plugin.h @@ -50,6 +50,8 @@ private: HWND m_hWnd; #endif + NPWindow * m_Window; + NPStream * m_pNPStream; NPBool m_bInitialized; nsI4xScriptablePlugin * m_pScriptablePeer; @@ -64,6 +66,8 @@ public: NPBool init(NPWindow* pNPWindow); void shut(); NPBool isInitialized(); + + int16 handleEvent(void* event); void showVersion(); void clear();