1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
44 //////////////////////////////////////
46 // general initialization and shutdown
48 NPError
NS_PluginInitialize()
50 return NPERR_NO_ERROR
;
53 void NS_PluginShutdown()
57 /////////////////////////////////////////////////////////////
59 // construction and destruction of our plugin instance object
61 nsPluginInstanceBase
* NS_NewPluginInstance(nsPluginCreateData
* aCreateDataStruct
)
63 if(!aCreateDataStruct
)
66 nsPluginInstance
* plugin
= new nsPluginInstance(aCreateDataStruct
->instance
);
70 void NS_DestroyPluginInstance(nsPluginInstanceBase
* aPlugin
)
73 delete (nsPluginInstance
*)aPlugin
;
76 ////////////////////////////////////////
78 // nsPluginInstance class implementation
80 nsPluginInstance::nsPluginInstance(NPP aInstance
) : nsPluginInstanceBase(),
87 nsPluginInstance::~nsPluginInstance()
91 static LRESULT CALLBACK
PluginWinProc(HWND
, UINT
, WPARAM
, LPARAM
);
92 static WNDPROC lpOldProc
= NULL
;
94 NPBool
nsPluginInstance::init(NPWindow
* aWindow
)
99 mhWnd
= (HWND
)aWindow
->window
;
103 // subclass window so we can intercept window messages and
104 // do our drawing to it
105 lpOldProc
= SubclassWindow(mhWnd
, (WNDPROC
)PluginWinProc
);
107 // associate window with our nsPluginInstance object so we can access
108 // it in the window procedure
109 SetWindowLong(mhWnd
, GWL_USERDATA
, (LONG
)this);
115 void nsPluginInstance::shut()
118 SubclassWindow(mhWnd
, lpOldProc
);
120 mInitialized
= FALSE
;
123 NPBool
nsPluginInstance::isInitialized()
128 const char * nsPluginInstance::getVersion()
130 return NPN_UserAgent(mInstance
);
133 static LRESULT CALLBACK
PluginWinProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
138 // draw a frame and display the string
140 HDC hdc
= BeginPaint(hWnd
, &ps
);
142 GetClientRect(hWnd
, &rc
);
143 FrameRect(hdc
, &rc
, GetStockBrush(BLACK_BRUSH
));
145 // get our plugin instance object and ask it for the version string
146 nsPluginInstance
*plugin
= (nsPluginInstance
*)GetWindowLong(hWnd
, GWL_USERDATA
);
148 const char * string
= plugin
->getVersion();
149 DrawText(hdc
, string
, strlen(string
), &rc
, DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
152 char string
[] = "Error occured";
153 DrawText(hdc
, string
, strlen(string
), &rc
, DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
163 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);