xref: /AOO41X/main/vcl/unx/kde4/KDEXLib.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #include <vos/process.hxx>
29 
30 #include "VCLKDEApplication.hxx"
31 
32 #define Region QtXRegion
33 
34 #include <kapplication.h>
35 #include <klocale.h>
36 #include <kaboutdata.h>
37 #include <kcmdlineargs.h>
38 #include <kstartupinfo.h>
39 
40 #undef Region
41 
42 #include "KDEXLib.hxx"
43 
44 #include <unx/i18n_im.hxx>
45 #include <unx/i18n_xkb.hxx>
46 
47 #include <unx/saldata.hxx>
48 
49 #include "KDESalDisplay.hxx"
50 
51 #if OSL_DEBUG_LEVEL > 1
52 #include <stdio.h>
53 #endif
54 
55 KDEXLib::KDEXLib() :
56 	SalXLib(),	m_bStartupDone(false), m_pApplication(0),
57 	m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 )
58 {
59 }
60 
61 KDEXLib::~KDEXLib()
62 {
63 	delete (VCLKDEApplication*)m_pApplication;
64 
65     // free the faked cmdline arguments no longer needed by KApplication
66     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
67 	{
68         free( m_pFreeCmdLineArgs[i] );
69 	}
70 
71     delete [] m_pFreeCmdLineArgs;
72     delete [] m_pAppCmdLineArgs;
73 }
74 
75 void KDEXLib::Init()
76 {
77 	SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
78 	pInputMethod->SetLocale();
79 	XrmInitialize();
80 
81 	KAboutData *kAboutData = new KAboutData("OpenOffice.org",
82 			"kdelibs4",
83 			ki18n( "OpenOffice.org" ),
84 			"3.0.0",
85 			ki18n( "OpenOffice.org with KDE Native Widget Support." ),
86 			KAboutData::License_LGPL,
87 			ki18n( "Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Novell, Inc"),
88 			ki18n( "OpenOffice.org is an office suite.\n" ),
89 			"http://kde.openoffice.org/index.html",
90 			"dev@kde.openoffice.org" );
91 
92 	kAboutData->addAuthor( ki18n( "Jan Holesovsky" ),
93 			ki18n( "Original author and maintainer of the KDE NWF." ),
94 			"kendy@artax.karlin.mff.cuni.cz",
95 			"http://artax.karlin.mff.cuni.cz/~kendy" );
96 	kAboutData->addAuthor( ki18n("Roman Shtylman"),
97 			ki18n( "Porting to KDE 4." ),
98 			"shtylman@gmail.com", "http://shtylman.com" );
99 	kAboutData->addAuthor( ki18n("Eric Bischoff"),
100 			ki18n( "Accessibility fixes, porting to KDE 4." ),
101 			"bischoff@kde.org" );
102 
103 	//kAboutData->setProgramIconName("OpenOffice");
104 
105 	m_nFakeCmdLineArgs = 1;
106 	int nIdx;
107 	vos::OExtCommandLine aCommandLine;
108 	int nParams = aCommandLine.getCommandArgCount();
109 	rtl::OString aDisplay;
110 	rtl::OUString aParam, aBin;
111 
112 	for ( nIdx = 0; nIdx < nParams; ++nIdx )
113 	{
114 		aCommandLine.getCommandArg( nIdx, aParam );
115 		if ( !m_pFreeCmdLineArgs && aParam.equalsAscii( "-display" ) && nIdx + 1 < nParams )
116 		{
117 			aCommandLine.getCommandArg( nIdx + 1, aParam );
118 			aDisplay = rtl::OUStringToOString( aParam, osl_getThreadTextEncoding() );
119 
120 			m_nFakeCmdLineArgs = 3;
121 			m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
122 			m_pFreeCmdLineArgs[ 1 ] = strdup( "-display" );
123 			m_pFreeCmdLineArgs[ 2 ] = strdup( aDisplay.getStr() );
124 		}
125 	}
126 	if ( !m_pFreeCmdLineArgs )
127 		m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
128 
129     osl_getExecutableFile( &aParam.pData );
130     osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
131     rtl::OString aExec = rtl::OUStringToOString( aBin, osl_getThreadTextEncoding() );
132 	m_pFreeCmdLineArgs[0] = strdup( aExec.getStr() );
133 
134     // make a copy of the string list for freeing it since
135     // KApplication manipulates the pointers inside the argument vector
136     // note: KApplication bad !
137     m_pAppCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
138     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
139         m_pAppCmdLineArgs[i] = m_pFreeCmdLineArgs[i];
140 
141 	KCmdLineArgs::init( m_nFakeCmdLineArgs, m_pAppCmdLineArgs, kAboutData );
142 
143 	m_pApplication = new VCLKDEApplication();
144 	kapp->disableSessionManagement();
145 	KApplication::setQuitOnLastWindowClosed(false);
146 
147 	Display* pDisp = QX11Info::display();
148 	SalKDEDisplay *pSalDisplay = new SalKDEDisplay(pDisp);
149 
150 	((VCLKDEApplication*)m_pApplication)->disp = pSalDisplay;
151 
152 	pInputMethod->CreateMethod( pDisp );
153 	pInputMethod->AddConnectionWatch( pDisp, (void*)this );
154 	pSalDisplay->SetInputMethod( pInputMethod );
155 
156     PushXErrorLevel( true );
157 	SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
158 	XSync( pDisp, False );
159 
160 	pKbdExtension->UseExtension( ! HasXErrorOccured() );
161 	PopXErrorLevel();
162 
163 	pSalDisplay->SetKbdExtension( pKbdExtension );
164 }
165 
166 void KDEXLib::doStartup()
167 {
168     if( ! m_bStartupDone )
169     {
170         KStartupInfo::appStarted();
171         m_bStartupDone = true;
172         #if OSL_DEBUG_LEVEL > 1
173         fprintf( stderr, "called KStartupInfo::appStarted()\n" );
174         #endif
175     }
176 }
177