Back to index

lightning-sunbird  0.9+nobinonly
plugin.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 #include <windows.h>
00040 #include <windowsx.h>
00041 
00042 #include "plugin.h"
00043 
00045 //
00046 // general initialization and shutdown
00047 //
00048 NPError NS_PluginInitialize()
00049 {
00050   return NPERR_NO_ERROR;
00051 }
00052 
00053 void NS_PluginShutdown()
00054 {
00055 }
00056 
00058 //
00059 // construction and destruction of our plugin instance object
00060 //
00061 nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
00062 {
00063   if(!aCreateDataStruct)
00064     return NULL;
00065 
00066   nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct->instance);
00067 
00068   // now is the time to tell Mozilla that we are windowless
00069   NPN_SetValue(aCreateDataStruct->instance, NPPVpluginWindowBool, NULL);
00070 
00071   return plugin;
00072 }
00073 
00074 void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
00075 {
00076   if(aPlugin)
00077     delete (nsPluginInstance *)aPlugin;
00078 }
00079 
00081 //
00082 // nsPluginInstance class implementation
00083 //
00084 nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
00085   mInstance(aInstance),
00086   mInitialized(FALSE)
00087 {
00088 }
00089 
00090 nsPluginInstance::~nsPluginInstance()
00091 {
00092 }
00093 
00094 NPBool nsPluginInstance::init(NPWindow* aWindow)
00095 {
00096   // no GUI to init in windowless case
00097   mInitialized = TRUE;
00098   return TRUE;
00099 }
00100 
00101 void nsPluginInstance::shut()
00102 {
00103   // no GUI to shut in windowless case
00104   mInitialized = FALSE;
00105 }
00106 
00107 NPBool nsPluginInstance::isInitialized()
00108 {
00109   return mInitialized;
00110 }
00111 
00112 NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
00113 {
00114   // keep window parameters
00115   mWindow = aWindow;
00116   return NPERR_NO_ERROR;
00117 }
00118 
00119 uint16 nsPluginInstance::HandleEvent(void* aEvent)
00120 {
00121   NPEvent * event = (NPEvent *)aEvent;
00122   switch (event->event) {
00123     case WM_PAINT: 
00124     {
00125       if(!mWindow)
00126         break;
00127 
00128       // get the dirty rectangle to update or repaint the whole window
00129       RECT * drc = (RECT *)event->lParam;
00130       if(drc)
00131         FillRect((HDC)event->wParam, drc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
00132       else {
00133         RECT rc;
00134         rc.bottom = mWindow->y + mWindow->height;
00135         rc.left   = mWindow->x;
00136         rc.right  = mWindow->x + mWindow->width;
00137         rc.top    = mWindow->y;
00138         FillRect((HDC)event->wParam, &rc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
00139       }
00140       break;
00141     }
00142     case WM_KEYDOWN:
00143     {
00144       Beep(1000,100);
00145       break;
00146     }
00147     default:
00148       return 0;
00149   }
00150   return 1;
00151 }