merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / kde / kdedata.cxx
blobed91c8ae5baa0148af0b4bd2c39040388d7bf92e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
31 #define _SV_SALDATA_CXX
32 #include "kde_headers.h"
34 #include <unistd.h>
35 #include <fcntl.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <limits.h>
41 #include <errno.h>
42 #include <poll.h>
43 #ifdef FREEBSD
44 #include <sys/types.h>
45 #include <sys/time.h>
46 #include <unistd.h>
47 #endif
48 #include <plugins/kde/kdedata.hxx>
49 #include <osl/thread.h>
50 #include <osl/process.h>
51 #include <osl/module.h>
53 #include <tools/debug.hxx>
54 #include "i18n_im.hxx"
55 #include "i18n_xkb.hxx"
56 #include <vos/process.hxx>
57 #ifndef _VOS_MUTEX_HXX
58 #include <vos/mutex.hxx>
59 #endif
61 /* #i59042# override KApplications method for session management
62 * since it will interfere badly with our own.
64 class VCLKDEApplication : public KApplication
66 public:
67 VCLKDEApplication() : KApplication() {}
69 virtual void commitData(QSessionManager &sm);
72 void VCLKDEApplication::commitData(QSessionManager&)
76 /***************************************************************************
77 * class SalKDEDisplay *
78 ***************************************************************************/
80 SalKDEDisplay::SalKDEDisplay( Display* pDisp )
81 : SalX11Display( pDisp )
85 SalKDEDisplay::~SalKDEDisplay()
87 // in case never a frame opened
88 static_cast<KDEXLib*>(GetXLib())->doStartup();
89 // clean up own members
90 doDestruct();
91 // prevent SalDisplay from closing KApplication's display
92 pDisp_ = NULL;
95 /***************************************************************************
96 * class KDEXLib *
97 ***************************************************************************/
99 KDEXLib::~KDEXLib()
101 // #158056# on 64 bit linux using libXRandr.so.2 will crash in
102 // XCloseDisplay when freeing extension data
103 // no known work around, therefor currently leak. Hopefully
104 // this does not make problems since we're shutting down anyway
105 // should we ever get a real kde plugin that uses the KDE event loop
106 // we should use kde's method to signal screen changes similar
107 // to the gtk plugin
108 #if ! defined USE_RANDR || ! (defined LINUX && defined X86_64)
109 // properly deinitialize KApplication
110 delete (VCLKDEApplication*)m_pApplication;
111 #endif
112 // free the faked cmdline arguments no longer needed by KApplication
113 for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
114 free( m_pFreeCmdLineArgs[i] );
115 delete [] m_pFreeCmdLineArgs;
116 delete [] m_pAppCmdLineArgs;
119 void KDEXLib::Init()
121 SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
122 pInputMethod->SetLocale();
123 XrmInitialize();
125 KAboutData *kAboutData = new KAboutData( "OpenOffice.org",
126 I18N_NOOP( "OpenOffice.org" ),
127 "1.1.0",
128 I18N_NOOP( "OpenOffice.org with KDE Native Widget Support." ),
129 KAboutData::License_LGPL,
130 "(c) 2003, 2004 Novell, Inc",
131 I18N_NOOP( "OpenOffice.org is an office suite.\n" ),
132 "http://kde.openoffice.org/index.html",
133 "dev@kde.openoffice.org");
134 kAboutData->addAuthor( "Jan Holesovsky",
135 I18N_NOOP( "Original author and maintainer of the KDE NWF." ),
136 "kendy@artax.karlin.mff.cuni.cz",
137 "http://artax.karlin.mff.cuni.cz/~kendy" );
139 m_nFakeCmdLineArgs = 1;
140 USHORT nIdx;
141 vos::OExtCommandLine aCommandLine;
142 int nParams = aCommandLine.getCommandArgCount();
143 rtl::OString aDisplay;
144 rtl::OUString aParam, aBin;
146 for ( nIdx = 0; nIdx < nParams; ++nIdx )
148 aCommandLine.getCommandArg( nIdx, aParam );
149 if ( !m_pFreeCmdLineArgs && aParam.equalsAscii( "-display" ) && nIdx + 1 < nParams )
151 aCommandLine.getCommandArg( nIdx + 1, aParam );
152 aDisplay = rtl::OUStringToOString( aParam, osl_getThreadTextEncoding() );
154 m_nFakeCmdLineArgs = 3;
155 m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
156 m_pFreeCmdLineArgs[ 1 ] = strdup( "-display" );
157 m_pFreeCmdLineArgs[ 2 ] = strdup( aDisplay.getStr() );
160 if ( !m_pFreeCmdLineArgs )
161 m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
163 osl_getExecutableFile( &aParam.pData );
164 osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
165 rtl::OString aExec = rtl::OUStringToOString( aBin, osl_getThreadTextEncoding() );
166 m_pFreeCmdLineArgs[0] = strdup( aExec.getStr() );
168 // make a copy of the string list for freeing it since
169 // KApplication manipulates the pointers inside the argument vector
170 // note: KApplication bad !
171 m_pAppCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
172 for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
173 m_pAppCmdLineArgs[i] = m_pFreeCmdLineArgs[i];
175 KCmdLineArgs::init( m_nFakeCmdLineArgs, m_pAppCmdLineArgs, kAboutData );
177 KApplication::disableAutoDcopRegistration();
178 m_pApplication = new VCLKDEApplication();
179 kapp->disableSessionManagement();
181 Display* pDisp = QPaintDevice::x11AppDisplay();
183 SalDisplay *pSalDisplay = new SalKDEDisplay( pDisp );
185 XSetIOErrorHandler ( (XIOErrorHandler)X11SalData::XIOErrorHdl );
186 XSetErrorHandler ( (XErrorHandler)X11SalData::XErrorHdl );
188 pInputMethod->CreateMethod( pDisp );
189 pInputMethod->AddConnectionWatch( pDisp, (void*)this );
190 pSalDisplay->SetInputMethod( pInputMethod );
192 PushXErrorLevel( true );
193 SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
194 XSync( pDisp, False );
196 pKbdExtension->UseExtension( ! HasXErrorOccured() );
197 PopXErrorLevel();
199 pSalDisplay->SetKbdExtension( pKbdExtension );
202 void KDEXLib::doStartup()
204 if( ! m_bStartupDone )
206 KStartupInfo::appStarted();
207 m_bStartupDone = true;
208 #if OSL_DEBUG_LEVEL > 1
209 fprintf( stderr, "called KStartupInfo::appStarted()\n" );
210 #endif
214 /**********************************************************************
215 * class KDEData *
216 **********************************************************************/
218 KDEData::~KDEData()
222 void KDEData::Init()
224 pXLib_ = new KDEXLib();
225 pXLib_->Init();
228 /**********************************************************************
229 * plugin entry point *
230 **********************************************************************/
232 extern "C" {
233 VCL_DLLPUBLIC SalInstance* create_SalInstance( oslModule )
235 /* #i92121# workaround deadlocks in the X11 implementation
237 static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
238 /* #i90094#
239 from now on we know that an X connection will be
240 established, so protect X against itself
242 if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
243 XInitThreads();
245 rtl::OString aVersion( qVersion() );
246 #if OSL_DEBUG_LEVEL > 1
247 fprintf( stderr, "qt version string is \"%s\"\n", aVersion.getStr() );
248 #endif
249 sal_Int32 nIndex = 0, nMajor = 0, nMinor = 0, nMicro = 0;
250 nMajor = aVersion.getToken( 0, '.', nIndex ).toInt32();
251 if( nIndex > 0 )
252 nMinor = aVersion.getToken( 0, '.', nIndex ).toInt32();
253 if( nIndex > 0 )
254 nMicro = aVersion.getToken( 0, '.', nIndex ).toInt32();
255 if( nMajor != 3 || nMinor < 2 || (nMinor == 2 && nMicro < 2) )
257 #if OSL_DEBUG_LEVEL > 1
258 fprintf( stderr, "unsuitable qt version %d.%d.%d\n", (int)nMajor, (int)nMinor, (int)nMicro );
259 #endif
260 return NULL;
263 KDESalInstance* pInstance = new KDESalInstance( new SalYieldMutex() );
264 #if OSL_DEBUG_LEVEL > 1
265 fprintf( stderr, "created KDESalInstance 0x%p\n", pInstance );
266 #endif
268 // initialize SalData
269 KDEData *pSalData = new KDEData();
270 SetSalData( pSalData );
271 pSalData->m_pInstance = pInstance;
272 pSalData->Init();
273 pSalData->initNWF();
275 return pInstance;