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 ***** */
40 #define MIME_TYPES_HANDLED "application/basic-plugin"
41 #define PLUGIN_NAME "Basic Example Plug-in for Mozilla"
42 #define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED":bsc:"PLUGIN_NAME
43 #define PLUGIN_DESCRIPTION PLUGIN_NAME " (Plug-ins SDK sample)"
46 char* NPP_GetMIMEDescription(void)
48 return(MIME_TYPES_DESCRIPTION
);
51 /////////////////////////////////////
52 // general initialization and shutdown
54 NPError
NS_PluginInitialize()
56 return NPERR_NO_ERROR
;
59 void NS_PluginShutdown()
63 // get values per plugin
64 NPError
NS_PluginGetValue(NPPVariable aVariable
, void *aValue
)
66 NPError err
= NPERR_NO_ERROR
;
68 case NPPVpluginNameString
:
69 *((char **)aValue
) = PLUGIN_NAME
;
71 case NPPVpluginDescriptionString
:
72 *((char **)aValue
) = PLUGIN_DESCRIPTION
;
75 err
= NPERR_INVALID_PARAM
;
81 /////////////////////////////////////////////////////////////
83 // construction and destruction of our plugin instance object
85 nsPluginInstanceBase
* NS_NewPluginInstance(nsPluginCreateData
* aCreateDataStruct
)
87 if(!aCreateDataStruct
)
90 nsPluginInstance
* plugin
= new nsPluginInstance(aCreateDataStruct
->instance
);
94 void NS_DestroyPluginInstance(nsPluginInstanceBase
* aPlugin
)
97 delete (nsPluginInstance
*)aPlugin
;
100 ////////////////////////////////////////
102 // nsPluginInstance class implementation
104 nsPluginInstance::nsPluginInstance(NPP aInstance
) : nsPluginInstanceBase(),
105 mInstance(aInstance
),
113 nsPluginInstance::~nsPluginInstance()
118 xt_event_handler(Widget xtwidget
, nsPluginInstance
*plugin
, XEvent
*xevent
, Boolean
*b
)
120 switch (xevent
->type
) {
122 // get rid of all other exposure events
124 //while(XCheckTypedWindowEvent(plugin->Display(), plugin->Window(), Expose, xevent));
132 void nsPluginInstance::draw()
134 unsigned int h
= mHeight
/2;
135 unsigned int w
= 3 * mWidth
/4;
136 int x
= (mWidth
- w
)/2; // center
138 if (x
>= 0 && y
>= 0) {
139 GC gc
= XCreateGC(mDisplay
, mWindow
, 0, NULL
);
142 XDrawRectangle(mDisplay
, mWindow
, gc
, x
, y
, w
, h
);
143 const char *string
= getVersion();
144 if (string
&& *string
) {
145 int l
= strlen(string
);
146 int fmba
= mFontInfo
->max_bounds
.ascent
;
147 int fmbd
= mFontInfo
->max_bounds
.descent
;
148 int fh
= fmba
+ fmbd
;
151 XDrawString(mDisplay
, mWindow
, gc
, x
, y
, string
, l
);
153 XFreeGC(mDisplay
, gc
);
157 NPBool
nsPluginInstance::init(NPWindow
* aWindow
)
162 if (SetWindow(aWindow
))
168 void nsPluginInstance::shut()
170 mInitialized
= FALSE
;
173 const char * nsPluginInstance::getVersion()
175 return NPN_UserAgent(mInstance
);
178 NPError
nsPluginInstance::GetValue(NPPVariable aVariable
, void *aValue
)
180 NPError err
= NPERR_NO_ERROR
;
182 case NPPVpluginNameString
:
183 case NPPVpluginDescriptionString
:
184 return NS_PluginGetValue(aVariable
, aValue
) ;
187 err
= NPERR_INVALID_PARAM
;
194 NPError
nsPluginInstance::SetWindow(NPWindow
* aWindow
)
201 mWidth
= aWindow
->width
;
202 mHeight
= aWindow
->height
;
203 if (mWindow
== (Window
) aWindow
->window
) {
204 // The page with the plugin is being resized.
205 // Save any UI information because the next time
206 // around expect a SetWindow with a new window id.
208 mWindow
= (Window
) aWindow
->window
;
209 NPSetWindowCallbackStruct
*ws_info
= (NPSetWindowCallbackStruct
*)aWindow
->ws_info
;
210 mDisplay
= ws_info
->display
;
211 mVisual
= ws_info
->visual
;
212 mDepth
= ws_info
->depth
;
213 mColormap
= ws_info
->colormap
;
216 if (!(mFontInfo
= XLoadQueryFont(mDisplay
, "9x15")))
217 printf("Cannot open 9X15 font\n");
219 // add xt event handler
220 Widget xtwidget
= XtWindowToWidget(mDisplay
, mWindow
);
221 if (xtwidget
&& mXtwidget
!= xtwidget
) {
222 mXtwidget
= xtwidget
;
223 long event_mask
= ExposureMask
;
224 XSelectInput(mDisplay
, mWindow
, event_mask
);
225 XtAddEventHandler(xtwidget
, event_mask
, False
, (XtEventHandler
)xt_event_handler
, this);