1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
44 #include <sys/types.h>
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>
61 /* #i59042# override KApplications method for session management
62 * since it will interfere badly with our own.
64 class VCLKDEApplication
: public KApplication
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
91 // prevent SalDisplay from closing KApplication's display
95 /***************************************************************************
97 ***************************************************************************/
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
108 #if ! defined USE_RANDR || ! (defined LINUX && defined X86_64)
109 // properly deinitialize KApplication
110 delete (VCLKDEApplication
*)m_pApplication
;
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
;
121 SalI18N_InputMethod
* pInputMethod
= new SalI18N_InputMethod
;
122 pInputMethod
->SetLocale();
125 KAboutData
*kAboutData
= new KAboutData( "OpenOffice.org",
126 I18N_NOOP( "OpenOffice.org" ),
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;
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() );
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" );
214 /**********************************************************************
216 **********************************************************************/
224 pXLib_
= new KDEXLib();
228 /**********************************************************************
229 * plugin entry point *
230 **********************************************************************/
233 VCL_DLLPUBLIC SalInstance
* create_SalInstance( oslModule
)
235 /* #i92121# workaround deadlocks in the X11 implementation
237 static const char* pNoXInitThreads
= getenv( "SAL_NO_XINITTHREADS" );
239 from now on we know that an X connection will be
240 established, so protect X against itself
242 if( ! ( pNoXInitThreads
&& *pNoXInitThreads
) )
245 rtl::OString
aVersion( qVersion() );
246 #if OSL_DEBUG_LEVEL > 1
247 fprintf( stderr
, "qt version string is \"%s\"\n", aVersion
.getStr() );
249 sal_Int32 nIndex
= 0, nMajor
= 0, nMinor
= 0, nMicro
= 0;
250 nMajor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
252 nMinor
= aVersion
.getToken( 0, '.', nIndex
).toInt32();
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
);
263 KDESalInstance
* pInstance
= new KDESalInstance( new SalYieldMutex() );
264 #if OSL_DEBUG_LEVEL > 1
265 fprintf( stderr
, "created KDESalInstance 0x%p\n", pInstance
);
268 // initialize SalData
269 KDEData
*pSalData
= new KDEData();
270 SetSalData( pSalData
);
271 pSalData
->m_pInstance
= pInstance
;