Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : ************************************************************************/
28 : #ifndef _PLUGCON_HXX
29 : #define _PLUGCON_HXX
30 :
31 : #include <stdarg.h>
32 : #include <string.h>
33 :
34 : #include <list>
35 : #include <vector>
36 : #include <plugin/unx/mediator.hxx>
37 :
38 : #if defined SOLARIS
39 : # define USE_MOTIF
40 : #endif
41 :
42 : #define Window XLIB_Window
43 : #define Font XLIB_Font
44 : #define KeyCode XLIB_KeyCode
45 : #define Time XLIB_Time
46 : #define Cursor XLIB_Cursor
47 : #define Region XLIB_Region
48 : #define String XLIB_String
49 : #define Boolean XLIB_Boolean
50 : #define XPointer XLIB_XPointer
51 : #include <X11/Xlib.h>
52 : extern "C" {
53 : #include <X11/Intrinsic.h>
54 : }
55 : #include <X11/Shell.h>
56 : #include <X11/IntrinsicP.h> /* Intrinsics Definitions*/
57 : #include <X11/StringDefs.h> /* Standard Name-String definitions*/
58 : #if defined USE_MOTIF
59 : #include <Xm/DrawingA.h>
60 : #else
61 : #include <X11/Composite.h>
62 : #endif
63 : #include <X11/Xatom.h>
64 : #ifndef XP_UNIX
65 : # define XP_UNIX
66 : #endif
67 : #define MOZ_X11
68 : #include <stdio.h>
69 : #ifdef SYSTEM_MOZILLA
70 : #ifndef OJI
71 : # define OJI
72 : #endif
73 : #define MOZ_X11
74 : #endif
75 :
76 : #if ! defined ( _NPAPI_H_) && ! defined (npapi_h_)
77 : extern "C" {
78 : #include <npsdk/npupp.h>
79 : }
80 : #include "npapi.h"
81 :
82 : #if NP_VERSION_MINOR < 17
83 : // compatibility hack: compile with older NPN api header, but define
84 : // some later introduced constants
85 : // for gcc 3
86 : #define NP_ABI_MASK 0x10000000
87 : #define NPNVSupportsXEmbedBool ((NPNVariable)14)
88 : #define NPPVpluginNeedsXEmbed ((NPPVariable)14)
89 : #define NPNVToolkit ((int)(13 | NP_ABI_MASK))
90 : #define NPNVGtk12 1
91 : #define NPNVGtk2 2
92 : #endif
93 : #endif
94 :
95 : #include <config_vclplug.h>
96 :
97 : #ifdef ENABLE_GTK
98 : #include <gtk/gtk.h>
99 : #include <gdk/gdkx.h>
100 : #else
101 : #define GtkWidget void
102 : #endif
103 :
104 : #undef Window
105 : #undef Font
106 : #undef KeyCode
107 : #undef Time
108 : #undef Cursor
109 : #undef String
110 : #undef Region
111 : #undef Boolean
112 : #undef XPointer
113 :
114 : class ConnectorInstance
115 : {
116 : public:
117 : NPP instance;
118 : NPWindow window;
119 : NPSetWindowCallbackStruct ws_info;
120 : char* pMimeType;
121 : void* pShell;
122 : void* pWidget;
123 : void* pForm;
124 :
125 : GtkWidget* pGtkWindow;
126 : GtkWidget* pGtkWidget;
127 :
128 : bool bShouldUseXEmbed;
129 :
130 : int nArg;
131 : char** argn;
132 : char** argv;
133 : char* pArgnBuf;
134 : char* pArgvBuf;
135 : NPSavedData aData;
136 :
137 : ConnectorInstance( NPP inst, char* type,
138 : int args, char* pargnbuf, sal_uLong nargnbytes,
139 : char* pargvbuf, sal_uLong nargvbytes,
140 : char* savedata, sal_uLong savebytes );
141 : ~ConnectorInstance();
142 : };
143 :
144 : class PluginConnector : public Mediator
145 : {
146 : protected:
147 : osl::Mutex m_aUserEventMutex;
148 :
149 : static std::vector<PluginConnector*> allConnectors;
150 :
151 : DECL_LINK( NewMessageHdl, Mediator* );
152 : DECL_LINK( WorkOnNewMessageHdl, Mediator* );
153 :
154 : std::vector<NPStream*> m_aNPWrapStreams;
155 : std::vector<ConnectorInstance*> m_aInstances;
156 :
157 : sal_uLong FillBuffer( char*&, const char*, sal_uLong, va_list );
158 : public:
159 : PluginConnector( int nSocket );
160 : virtual ~PluginConnector();
161 :
162 : virtual MediatorMessage* WaitForAnswer( sal_uLong nMessageID );
163 : MediatorMessage* Transact( const char*, sal_uLong, ... );
164 : MediatorMessage* Transact( sal_uInt32, ... );
165 : void Respond( sal_uLong nID, char*, sal_uLong, ... );
166 : sal_uLong Send( sal_uInt32, ... );
167 :
168 : static const sal_uInt32 UnknownStreamID = 0xffffffff;
169 : static const sal_uInt32 UnknownNPPID = 0xffffffff;
170 :
171 : sal_uInt32 GetStreamID( NPStream* pStream );
172 : sal_uInt32 GetNPPID( NPP );
173 :
174 0 : std::vector<NPStream*>& getStreamList() { return m_aNPWrapStreams; }
175 :
176 0 : NPError GetNPError( MediatorMessage* pMes )
177 : {
178 0 : NPError* pErr = (NPError*)pMes->GetBytes();
179 0 : NPError aErr = *pErr;
180 0 : delete [] pErr;
181 0 : return aErr;
182 : }
183 :
184 0 : void CallWorkHandler()
185 : {
186 : LINK( this, PluginConnector, WorkOnNewMessageHdl ).
187 0 : Call( (Mediator*)this );
188 0 : }
189 : };
190 :
191 : enum CommandAtoms
192 : {
193 : eNPN_GetURL,
194 : eNPN_GetURLNotify,
195 : eNPN_DestroyStream,
196 : eNPN_NewStream,
197 : eNPN_PostURLNotify,
198 : eNPN_PostURL,
199 : eNPN_RequestRead,
200 : eNPN_Status,
201 : eNPN_Version,
202 : eNPN_Write,
203 : eNPN_UserAgent,
204 :
205 : eNPP_DestroyStream,
206 : eNPP_Destroy,
207 : eNPP_DestroyPhase2,
208 : eNPP_NewStream,
209 : eNPP_New,
210 : eNPP_SetWindow,
211 : eNPP_StreamAsFile,
212 : eNPP_URLNotify,
213 : eNPP_WriteReady,
214 : eNPP_Write,
215 : eNPP_GetMIMEDescription,
216 : eNPP_Initialize,
217 : eNPP_Shutdown,
218 :
219 : eMaxCommand
220 : };
221 :
222 : const char* GetCommandName( CommandAtoms );
223 :
224 : #define POST_STRING( x ) x ? x : const_cast<char*>(""), x ? strlen(x) : 1
225 :
226 : #endif // _PLUGCON_HXX
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|