diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic Plugin.mcp b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic Plugin.mcp new file mode 100644 index 00000000000..0b72c7db8de Binary files /dev/null and b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic Plugin.mcp differ diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic.rsrc b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic.rsrc new file mode 100644 index 00000000000..9545e6663be Binary files /dev/null and b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/Basic.rsrc differ diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.cpp index 455eca79ad3..e4f85845186 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.cpp +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.cpp @@ -35,9 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ +#include "plugin.h" #include -#include "plugin.h" + +#if !TARGET_API_MAC_CARBON +extern QDGlobals* gQDPtr; +#endif ////////////////////////////////////// @@ -94,6 +98,7 @@ NPBool nsPluginInstance::init(NPWindow* aWindow) mWindow = aWindow; mInitialized = TRUE; + mSaveClip = NewRgn(); return TRUE; } @@ -113,16 +118,51 @@ const char * nsPluginInstance::getVersion() return NPN_UserAgent(mInstance); } -CGrafPort gSavePort; -CGrafPtr gOldPort; +///////////////////////////////////////////////////////////// +// +// DrawString +// +void +nsPluginInstance::DrawString(const unsigned char* text, + short width, + short height, + short centerX, + Rect drawRect) +{ + short length, textHeight, textWidth; + + if(text == NULL) + return; + + length = strlen((char*)text); + TextFont(1); + TextFace(bold); + TextMode(srcCopy); + TextSize(12); + + FontInfo fontInfo; + GetFontInfo(&fontInfo); -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * DoDraw - +++++++++++++++++++++++++++++++++++++++++++++++++*/ + textHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading; + textWidth = TextWidth(text, 0, length); + + if (width > textWidth && height > textHeight) + { + MoveTo(centerX - (textWidth >> 1), height >> 1); + DrawText(text, 0, length); + } +} + +///////////////////////////////////////////////////////////// +// +// DoDraw - paint +// void nsPluginInstance::DoDraw(void) { Rect drawRect; + RGBColor black = { 0x0000, 0x0000, 0x0000 }; + RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF }; SInt32 height = mWindow->height; SInt32 width = mWindow->width; SInt32 centerX = (width) >> 1; @@ -131,23 +171,32 @@ nsPluginInstance::DoDraw(void) const char * ua = getVersion(); char* pascalString = (char*) NPN_MemAlloc(strlen(ua) + 1); strcpy(pascalString, ua); - + UInt8 *pTheText = (unsigned char*) ua; + drawRect.top = 0; drawRect.left = 0; drawRect.bottom = drawRect.top + height; drawRect.right = drawRect.left + width; - - EraseRect(&drawRect); + + PenNormal(); + RGBForeColor(&black); + RGBBackColor(&white); + +#if !TARGET_API_MAC_CARBON + FillRect(&drawRect, &(gQDPtr->white)); +#else + Pattern qdWhite; + FillRect(&drawRect, GetQDGlobalsWhite(&qdWhite)); +#endif + FrameRect(&drawRect); - MoveTo( centerX - 0.5 * StringWidth(c2pstr(pascalString)), centerY ); - DrawString(c2pstr(pascalString)); + DrawString(pTheText, width, height, centerX, drawRect); } -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * PlatformSetWindow - * - * Perform platform-specific window operations - +++++++++++++++++++++++++++++++++++++++++++++++++*/ +///////////////////////////////////////////////////////////// +// +// SetWindow +// NPError nsPluginInstance::SetWindow(NPWindow* window) { @@ -159,11 +208,10 @@ nsPluginInstance::SetWindow(NPWindow* window) return NPERR_NO_ERROR; } -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * PlatformHandleEvent - * - * Handle platform-specific events. - +++++++++++++++++++++++++++++++++++++++++++++++++*/ +///////////////////////////////////////////////////////////// +// +// HandleEvent +// uint16 nsPluginInstance::HandleEvent(void* event) { @@ -192,70 +240,56 @@ nsPluginInstance::HandleEvent(void* event) return eventHandled; } -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * StartDraw - +++++++++++++++++++++++++++++++++++++++++++++++++*/ +///////////////////////////////////////////////////////////// +// +// StartDraw - setup port state +// NPBool nsPluginInstance::StartDraw(NPWindow* window) { - NP_Port* port; - Rect clipRect; - RGBColor col; + if (mWindow == NULL) + return false; + + NP_Port* npport = (NP_Port*) mWindow->window; + CGrafPtr ourPort = npport->port; - if (window == NULL) - return FALSE; - port = (NP_Port*) window->window; - if (window->clipRect.left < window->clipRect.right) + if (mWindow->clipRect.left < mWindow->clipRect.right) { - /* Preserve the old port */ - GetPort((GrafPtr*)&gOldPort); - SetPort((GrafPtr)port->port); - /* Preserve the old drawing environment */ - gSavePort.portRect = port->port->portRect; - gSavePort.txFont = port->port->txFont; - gSavePort.txFace = port->port->txFace; - gSavePort.txMode = port->port->txMode; - gSavePort.rgbFgColor = port->port->rgbFgColor; - gSavePort.rgbBkColor = port->port->rgbBkColor; - GetClip(gSavePort.clipRgn); - /* Setup our drawing environment */ - clipRect.top = window->clipRect.top + port->porty; - clipRect.left = window->clipRect.left + port->portx; - clipRect.bottom = window->clipRect.bottom + port->porty; - clipRect.right = window->clipRect.right + port->portx; - SetOrigin(port->portx,port->porty); - ClipRect(&clipRect); - clipRect.top = clipRect.left = 0; - TextSize(12); - TextFont(20); - TextMode(srcCopy); - col.red = col.green = col.blue = 0; - RGBForeColor(&col); - col.red = col.green = col.blue = 65000; - RGBBackColor(&col); - return TRUE; + GetPort(&mSavePort); + SetPort((GrafPtr) ourPort); + Rect portRect; +#if !TARGET_API_MAC_CARBON + portRect = ourPort->portRect; +#else + GetPortBounds(ourPort, &portRect); +#endif + mSavePortTop = portRect.top; + mSavePortLeft = portRect.left; + GetClip(mSaveClip); + + mRevealedRect.top = mWindow->clipRect.top + npport->porty; + mRevealedRect.left = mWindow->clipRect.left + npport->portx; + mRevealedRect.bottom = mWindow->clipRect.bottom + npport->porty; + mRevealedRect.right = mWindow->clipRect.right + npport->portx; + SetOrigin(npport->portx, npport->porty); + ClipRect(&mRevealedRect); + + return true; } else - return FALSE; + return false; } -/*+++++++++++++++++++++++++++++++++++++++++++++++++ - * EndDraw - +++++++++++++++++++++++++++++++++++++++++++++++++*/ +///////////////////////////////////////////////////////////// +// +// EndDraw - restore port state +// void nsPluginInstance::EndDraw(NPWindow* window) { - CGrafPtr myPort; - NP_Port* port = (NP_Port*) window->window; - SetOrigin(gSavePort.portRect.left, gSavePort.portRect.top); - SetClip(gSavePort.clipRgn); - GetPort((GrafPtr*)&myPort); - myPort->txFont = gSavePort.txFont; - myPort->txFace = gSavePort.txFace; - myPort->txMode = gSavePort.txMode; - RGBForeColor(&gSavePort.rgbFgColor); - RGBBackColor(&gSavePort.rgbBkColor); - SetPort((GrafPtr)gOldPort); + SetOrigin(mSavePortLeft, mSavePortTop); + SetClip(mSaveClip); + SetPort(mSavePort); } diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.h index b55c2845e72..9991add8dec 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.h +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/plugin.h @@ -52,17 +52,22 @@ public: NPError SetWindow(NPWindow* pNPWindow); uint16 HandleEvent(void* event); +private: // locals const char * getVersion(); void DoDraw(); - NPWindow * mWindow; - -private: NPBool StartDraw(NPWindow* window); void EndDraw(NPWindow* window); + void DrawString(const unsigned char* text, short width, short height, short centerX, Rect drawRect); + NPWindow * mWindow; NPP mInstance; NPBool mInitialized; + GrafPtr mSavePort; + RgnHandle mSaveClip; + Rect mRevealedRect; + short mSavePortTop; + short mSavePortLeft; }; #endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginCarbonPrefix.h b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginCarbonPrefix.h new file mode 100644 index 00000000000..d97f591353d --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginCarbonPrefix.h @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#define XP_MAC 1 +#define TARGET_CARBON 1 diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginPrefix.h b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginPrefix.h index 0afe657027b..7c398a5d7e9 100644 --- a/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginPrefix.h +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/mac/pluginPrefix.h @@ -20,6 +20,4 @@ * Contributor(s): */ -// #include "MacSharedPrefix.h" - #define XP_MAC 1