Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / sdk / samples / winless / windows / plugin.cpp
blobb86aef1cf062a322354657b9d033fb6097609a52
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
39 #include <windows.h>
40 #include <windowsx.h>
42 #include "plugin.h"
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)
64 return NULL;
66 nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct->instance);
68 // now is the time to tell Mozilla that we are windowless
69 NPN_SetValue(aCreateDataStruct->instance, NPPVpluginWindowBool, NULL);
71 return plugin;
74 void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
76 if(aPlugin)
77 delete (nsPluginInstance *)aPlugin;
80 ////////////////////////////////////////
82 // nsPluginInstance class implementation
84 nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
85 mInstance(aInstance),
86 mInitialized(FALSE)
90 nsPluginInstance::~nsPluginInstance()
94 NPBool nsPluginInstance::init(NPWindow* aWindow)
96 // no GUI to init in windowless case
97 mInitialized = TRUE;
98 return TRUE;
101 void nsPluginInstance::shut()
103 // no GUI to shut in windowless case
104 mInitialized = FALSE;
107 NPBool nsPluginInstance::isInitialized()
109 return mInitialized;
112 NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
114 // keep window parameters
115 mWindow = aWindow;
116 return NPERR_NO_ERROR;
119 uint16_t nsPluginInstance::HandleEvent(void* aEvent)
121 NPEvent * event = (NPEvent *)aEvent;
122 switch (event->event) {
123 case WM_PAINT:
125 if(!mWindow)
126 break;
128 // get the dirty rectangle to update or repaint the whole window
129 RECT * drc = (RECT *)event->lParam;
130 if(drc)
131 FillRect((HDC)event->wParam, drc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
132 else {
133 RECT rc;
134 rc.bottom = mWindow->y + mWindow->height;
135 rc.left = mWindow->x;
136 rc.right = mWindow->x + mWindow->width;
137 rc.top = mWindow->y;
138 FillRect((HDC)event->wParam, &rc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
140 break;
142 case WM_KEYDOWN:
144 Beep(1000,100);
145 break;
147 default:
148 return 0;
150 return 1;