merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / kde4 / KDEXLib.cxx
blobad5a8fb36b53c6545449d78df3f6bddff9225871
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2009 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 #include "VCLKDEApplication.hxx"
30 #define Region QtXRegion
32 #include <kapplication.h>
33 #include <klocale.h>
34 #include <kaboutdata.h>
35 #include <kcmdlineargs.h>
36 #include <kstartupinfo.h>
38 #undef Region
40 #include "KDEXLib.hxx"
42 #include <i18n_im.hxx>
43 #include <i18n_xkb.hxx>
45 #include <saldata.hxx>
46 #include <vos/process.hxx>
48 #include "KDESalDisplay.hxx"
50 #if OSL_DEBUG_LEVEL > 1
51 #include <stdio.h>
52 #endif
54 KDEXLib::KDEXLib() :
55 SalXLib(), m_bStartupDone(false), m_pApplication(0),
56 m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 )
60 KDEXLib::~KDEXLib()
62 delete (VCLKDEApplication*)m_pApplication;
64 // free the faked cmdline arguments no longer needed by KApplication
65 for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
67 free( m_pFreeCmdLineArgs[i] );
70 delete [] m_pFreeCmdLineArgs;
71 delete [] m_pAppCmdLineArgs;
74 void KDEXLib::Init()
76 SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
77 pInputMethod->SetLocale();
78 XrmInitialize();
80 KAboutData *kAboutData = new KAboutData("OpenOffice.org",
81 "kdelibs4",
82 ki18n( "OpenOffice.org" ),
83 "3.0.0",
84 ki18n( "OpenOffice.org with KDE Native Widget Support." ),
85 KAboutData::License_LGPL,
86 ki18n( "Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Novell, Inc"),
87 ki18n( "OpenOffice.org is an office suite.\n" ),
88 "http://kde.openoffice.org/index.html",
89 "dev@kde.openoffice.org" );
91 kAboutData->addAuthor( ki18n( "Jan Holesovsky" ),
92 ki18n( "Original author and maintainer of the KDE NWF." ),
93 "kendy@artax.karlin.mff.cuni.cz",
94 "http://artax.karlin.mff.cuni.cz/~kendy" );
95 kAboutData->addAuthor( ki18n("Roman Shtylman"),
96 ki18n( "Porting to KDE 4." ),
97 "shtylman@gmail.com", "http://shtylman.com" );
98 kAboutData->addAuthor( ki18n("Eric Bischoff"),
99 ki18n( "Accessibility fixes, porting to KDE 4." ),
100 "bischoff@kde.org" );
102 //kAboutData->setProgramIconName("OpenOffice");
104 m_nFakeCmdLineArgs = 1;
105 USHORT nIdx;
106 vos::OExtCommandLine aCommandLine;
107 int nParams = aCommandLine.getCommandArgCount();
108 rtl::OString aDisplay;
109 rtl::OUString aParam, aBin;
111 for ( nIdx = 0; nIdx < nParams; ++nIdx )
113 aCommandLine.getCommandArg( nIdx, aParam );
114 if ( !m_pFreeCmdLineArgs && aParam.equalsAscii( "-display" ) && nIdx + 1 < nParams )
116 aCommandLine.getCommandArg( nIdx + 1, aParam );
117 aDisplay = rtl::OUStringToOString( aParam, osl_getThreadTextEncoding() );
119 m_nFakeCmdLineArgs = 3;
120 m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
121 m_pFreeCmdLineArgs[ 1 ] = strdup( "-display" );
122 m_pFreeCmdLineArgs[ 2 ] = strdup( aDisplay.getStr() );
125 if ( !m_pFreeCmdLineArgs )
126 m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
128 osl_getExecutableFile( &aParam.pData );
129 osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
130 rtl::OString aExec = rtl::OUStringToOString( aBin, osl_getThreadTextEncoding() );
131 m_pFreeCmdLineArgs[0] = strdup( aExec.getStr() );
133 // make a copy of the string list for freeing it since
134 // KApplication manipulates the pointers inside the argument vector
135 // note: KApplication bad !
136 m_pAppCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
137 for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
138 m_pAppCmdLineArgs[i] = m_pFreeCmdLineArgs[i];
140 KCmdLineArgs::init( m_nFakeCmdLineArgs, m_pAppCmdLineArgs, kAboutData );
142 m_pApplication = new VCLKDEApplication();
143 kapp->disableSessionManagement();
144 KApplication::setQuitOnLastWindowClosed(false);
146 Display* pDisp = QX11Info::display();
147 SalKDEDisplay *pSalDisplay = new SalKDEDisplay(pDisp);
149 ((VCLKDEApplication*)m_pApplication)->disp = pSalDisplay;
151 XSetIOErrorHandler ( (XIOErrorHandler)X11SalData::XIOErrorHdl );
152 XSetErrorHandler ( (XErrorHandler)X11SalData::XErrorHdl );
154 pInputMethod->CreateMethod( pDisp );
155 pInputMethod->AddConnectionWatch( pDisp, (void*)this );
156 pSalDisplay->SetInputMethod( pInputMethod );
158 PushXErrorLevel( true );
159 SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
160 XSync( pDisp, False );
162 pKbdExtension->UseExtension( ! HasXErrorOccured() );
163 PopXErrorLevel();
165 pSalDisplay->SetKbdExtension( pKbdExtension );
168 void KDEXLib::doStartup()
170 if( ! m_bStartupDone )
172 KStartupInfo::appStarted();
173 m_bStartupDone = true;
174 #if OSL_DEBUG_LEVEL > 1
175 fprintf( stderr, "called KStartupInfo::appStarted()\n" );
176 #endif