xref: /aoo41x/main/vcl/unx/generic/app/salinst.cxx (revision c82f2877)
1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir #include <stdlib.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "osl/module.hxx"
32cdf0e10cSrcweir #include "tools/solarmutex.hxx"
33cdf0e10cSrcweir #include "vos/mutex.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "unx/salunx.h"
37cdf0e10cSrcweir #include "unx/saldata.hxx"
38cdf0e10cSrcweir #include "unx/saldisp.hxx"
39cdf0e10cSrcweir #include "unx/salinst.h"
40cdf0e10cSrcweir #include "unx/salframe.h"
41cdf0e10cSrcweir #include "unx/dtint.hxx"
42cdf0e10cSrcweir #include "unx/salprn.h"
43cdf0e10cSrcweir #include "unx/sm.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "vcl/apptypes.hxx"
46cdf0e10cSrcweir #include "vcl/helper.hxx"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "salwtype.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // -------------------------------------------------------------------------
51cdf0e10cSrcweir //
52cdf0e10cSrcweir // SalYieldMutex
53cdf0e10cSrcweir //
54cdf0e10cSrcweir // -------------------------------------------------------------------------
55cdf0e10cSrcweir 
SalYieldMutex()56cdf0e10cSrcweir SalYieldMutex::SalYieldMutex()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	mnCount 	= 0;
59cdf0e10cSrcweir 	mnThreadId	= 0;
60cdf0e10cSrcweir 	::tools::SolarMutex::SetSolarMutex( this );
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
acquire()63cdf0e10cSrcweir void SalYieldMutex::acquire()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	OMutex::acquire();
66cdf0e10cSrcweir 	mnThreadId = vos::OThread::getCurrentIdentifier();
67cdf0e10cSrcweir 	mnCount++;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
release()70cdf0e10cSrcweir void SalYieldMutex::release()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	if ( mnThreadId == vos::OThread::getCurrentIdentifier() )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		if ( mnCount == 1 )
75cdf0e10cSrcweir 			mnThreadId = 0;
76cdf0e10cSrcweir 		mnCount--;
77cdf0e10cSrcweir 	}
78cdf0e10cSrcweir 	OMutex::release();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
tryToAcquire()81cdf0e10cSrcweir sal_Bool SalYieldMutex::tryToAcquire()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	if ( OMutex::tryToAcquire() )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		mnThreadId = vos::OThread::getCurrentIdentifier();
86cdf0e10cSrcweir 		mnCount++;
87cdf0e10cSrcweir 		return True;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 	else
90cdf0e10cSrcweir 		return False;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //----------------------------------------------------------------------------
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // -=-= SalInstance =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
96cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
97cdf0e10cSrcweir 
98cdf0e10cSrcweir // plugin factory function
99cdf0e10cSrcweir extern "C"
100cdf0e10cSrcweir {
create_SalInstance()101cdf0e10cSrcweir     VCLPLUG_GEN_PUBLIC SalInstance* create_SalInstance()
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         /* #i92121# workaround deadlocks in the X11 implementation
104cdf0e10cSrcweir         */
105cdf0e10cSrcweir         static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
106cdf0e10cSrcweir         /* #i90094#
107cdf0e10cSrcweir            from now on we know that an X connection will be
108cdf0e10cSrcweir            established, so protect X against itself
109cdf0e10cSrcweir         */
110cdf0e10cSrcweir         if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
111cdf0e10cSrcweir             XInitThreads();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         X11SalInstance* pInstance = new X11SalInstance( new SalYieldMutex() );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // initialize SalData
116cdf0e10cSrcweir         X11SalData *pSalData = new X11SalData;
117cdf0e10cSrcweir         SetSalData( pSalData );
118cdf0e10cSrcweir         pSalData->m_pInstance = pInstance;
119cdf0e10cSrcweir         pSalData->Init();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         return pInstance;
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
~X11SalInstance()125cdf0e10cSrcweir X11SalInstance::~X11SalInstance()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     // close session management
128cdf0e10cSrcweir     SessionManagerClient::close();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     // dispose SalDisplay list from SalData
131cdf0e10cSrcweir     // would be done in a static destructor else which is
132cdf0e10cSrcweir     // a little late
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	X11SalData *pSalData = GetX11SalData();
135cdf0e10cSrcweir     pSalData->deInitNWF();
136cdf0e10cSrcweir 	delete pSalData;
137cdf0e10cSrcweir 	SetSalData( NULL );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	::tools::SolarMutex::SetSolarMutex( 0 );
140cdf0e10cSrcweir   	delete mpSalYieldMutex;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // --------------------------------------------------------
145cdf0e10cSrcweir // AnyInput from sv/mow/source/app/svapp.cxx
146cdf0e10cSrcweir 
147cdf0e10cSrcweir struct PredicateReturn
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	sal_uInt16	nType;
150cdf0e10cSrcweir 	sal_Bool	bRet;
151cdf0e10cSrcweir };
152cdf0e10cSrcweir 
153cdf0e10cSrcweir extern "C" {
ImplPredicateEvent(Display *,XEvent * pEvent,char * pData)154cdf0e10cSrcweir Bool ImplPredicateEvent( Display *, XEvent *pEvent, char *pData )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	PredicateReturn *pPre = (PredicateReturn *)pData;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	if ( pPre->bRet )
159cdf0e10cSrcweir 		return False;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	sal_uInt16 nType;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	switch( pEvent->type )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		case ButtonPress:
166cdf0e10cSrcweir 		case ButtonRelease:
167cdf0e10cSrcweir 		case MotionNotify:
168cdf0e10cSrcweir 		case EnterNotify:
169cdf0e10cSrcweir 		case LeaveNotify:
170cdf0e10cSrcweir 			nType = INPUT_MOUSE;
171cdf0e10cSrcweir 			break;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		case XLIB_KeyPress:
174cdf0e10cSrcweir 		//case KeyRelease:
175cdf0e10cSrcweir 			nType = INPUT_KEYBOARD;
176cdf0e10cSrcweir 			break;
177cdf0e10cSrcweir 		case Expose:
178cdf0e10cSrcweir 		case GraphicsExpose:
179cdf0e10cSrcweir 		case NoExpose:
180cdf0e10cSrcweir 			nType = INPUT_PAINT;
181cdf0e10cSrcweir 			break;
182cdf0e10cSrcweir 		default:
183cdf0e10cSrcweir 			nType = 0;
184cdf0e10cSrcweir 	}
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	if ( (nType & pPre->nType) || ( ! nType && (pPre->nType & INPUT_OTHER) ) )
187cdf0e10cSrcweir 		pPre->bRet = sal_True;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	return False;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
AnyInput(sal_uInt16 nType)193cdf0e10cSrcweir bool X11SalInstance::AnyInput(sal_uInt16 nType)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	X11SalData *pSalData = GetX11SalData();
196cdf0e10cSrcweir 	Display *pDisplay  = pSalData->GetDisplay()->GetDisplay();
197cdf0e10cSrcweir     sal_Bool bRet = sal_False;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     if( (nType & INPUT_TIMER) &&
200cdf0e10cSrcweir         pSalData->GetDisplay()->GetXLib()->CheckTimeout( false ) )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         bRet = sal_True;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 	else if (XPending(pDisplay) )
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir         PredicateReturn aInput;
207cdf0e10cSrcweir         XEvent			aEvent;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         aInput.bRet 	= sal_False;
210cdf0e10cSrcweir         aInput.nType	= nType;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         XCheckIfEvent(pDisplay, &aEvent, ImplPredicateEvent,
213cdf0e10cSrcweir                       (char *)&aInput );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         bRet = aInput.bRet;
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir 	return bRet;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
GetYieldMutex()220cdf0e10cSrcweir vos::IMutex* X11SalInstance::GetYieldMutex()
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	return mpSalYieldMutex;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir // -----------------------------------------------------------------------
226cdf0e10cSrcweir 
ReleaseYieldMutex()227cdf0e10cSrcweir sal_uLong X11SalInstance::ReleaseYieldMutex()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	SalYieldMutex* pYieldMutex = mpSalYieldMutex;
230cdf0e10cSrcweir 	if ( pYieldMutex->GetThreadId() ==
231cdf0e10cSrcweir 		 vos::OThread::getCurrentIdentifier() )
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir 		sal_uLong nCount = pYieldMutex->GetAcquireCount();
234cdf0e10cSrcweir 		sal_uLong n = nCount;
235cdf0e10cSrcweir 		while ( n )
236cdf0e10cSrcweir 		{
237cdf0e10cSrcweir 			pYieldMutex->release();
238cdf0e10cSrcweir 			n--;
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		return nCount;
242cdf0e10cSrcweir 	}
243cdf0e10cSrcweir 	else
244cdf0e10cSrcweir 		return 0;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir // -----------------------------------------------------------------------
248cdf0e10cSrcweir 
AcquireYieldMutex(sal_uLong nCount)249cdf0e10cSrcweir void X11SalInstance::AcquireYieldMutex( sal_uLong nCount )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	SalYieldMutex* pYieldMutex = mpSalYieldMutex;
252cdf0e10cSrcweir 	while ( nCount )
253cdf0e10cSrcweir 	{
254cdf0e10cSrcweir 		pYieldMutex->acquire();
255cdf0e10cSrcweir 		nCount--;
256cdf0e10cSrcweir 	}
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -----------------------------------------------------------------------
260cdf0e10cSrcweir 
CheckYieldMutex()261cdf0e10cSrcweir bool X11SalInstance::CheckYieldMutex()
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     bool bRet = true;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	SalYieldMutex* pYieldMutex = mpSalYieldMutex;
266cdf0e10cSrcweir 	if ( pYieldMutex->GetThreadId() !=
267cdf0e10cSrcweir 		 vos::OThread::getCurrentIdentifier() )
268cdf0e10cSrcweir 	{
269cdf0e10cSrcweir 	    bRet = false;
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     return bRet;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir // -----------------------------------------------------------------------
276cdf0e10cSrcweir 
Yield(bool bWait,bool bHandleAllCurrentEvents)277cdf0e10cSrcweir void X11SalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
278cdf0e10cSrcweir { GetX11SalData()->GetLib()->Yield( bWait, bHandleAllCurrentEvents ); }
279cdf0e10cSrcweir 
GetConnectionIdentifier(ConnectionIdentifierType & rReturnedType,int & rReturnedBytes)280cdf0e10cSrcweir void* X11SalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	static const char* pDisplay = getenv( "DISPLAY" );
283cdf0e10cSrcweir 	rReturnedType	= AsciiCString;
284cdf0e10cSrcweir 	rReturnedBytes	= pDisplay ? strlen( pDisplay )+1 : 1;
285cdf0e10cSrcweir 	return pDisplay ? (void*)pDisplay : (void*)"";
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
CreateFrame(SalFrame * pParent,sal_uLong nSalFrameStyle)288cdf0e10cSrcweir SalFrame *X11SalInstance::CreateFrame( SalFrame *pParent, sal_uLong nSalFrameStyle )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	SalFrame *pFrame = new X11SalFrame( pParent, nSalFrameStyle );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	return pFrame;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
CreateChildFrame(SystemParentData * pParentData,sal_uLong nStyle)295cdf0e10cSrcweir SalFrame* X11SalInstance::CreateChildFrame( SystemParentData* pParentData, sal_uLong nStyle )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	SalFrame* pFrame = new X11SalFrame( NULL, nStyle, pParentData );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	return pFrame;
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
DestroyFrame(SalFrame * pFrame)302cdf0e10cSrcweir void X11SalInstance::DestroyFrame( SalFrame* pFrame )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	delete pFrame;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
getServerDirectories(std::list<rtl::OString> & o_rFontPaths)307cdf0e10cSrcweir static void getServerDirectories( std::list< rtl::OString >& o_rFontPaths )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir #ifdef LINUX
310cdf0e10cSrcweir     /*
311cdf0e10cSrcweir      *  chkfontpath exists on some (RH derived) Linux distributions
312cdf0e10cSrcweir      */
313cdf0e10cSrcweir     static const char* pCommands[] = {
314cdf0e10cSrcweir         "/usr/sbin/chkfontpath 2>/dev/null", "chkfontpath 2>/dev/null"
315cdf0e10cSrcweir     };
316cdf0e10cSrcweir     ::std::list< ByteString > aLines;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir     for( unsigned int i = 0; i < sizeof(pCommands)/sizeof(pCommands[0]); i++ )
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         FILE* pPipe = popen( pCommands[i], "r" );
321cdf0e10cSrcweir         aLines.clear();
322cdf0e10cSrcweir         if( pPipe )
323cdf0e10cSrcweir         {
324cdf0e10cSrcweir             char line[1024];
325cdf0e10cSrcweir             char* pSearch;
326cdf0e10cSrcweir             while( fgets( line, sizeof(line), pPipe ) )
327cdf0e10cSrcweir             {
328cdf0e10cSrcweir                 int nLen = strlen( line );
329cdf0e10cSrcweir                 if( line[nLen-1] == '\n' )
330cdf0e10cSrcweir                     line[nLen-1] = 0;
331cdf0e10cSrcweir                 pSearch = strstr( line, ": " );
332cdf0e10cSrcweir                 if( pSearch )
333cdf0e10cSrcweir                     aLines.push_back( pSearch+2 );
334cdf0e10cSrcweir             }
335cdf0e10cSrcweir             if( ! pclose( pPipe ) )
336cdf0e10cSrcweir                 break;
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     for( ::std::list< ByteString >::iterator it = aLines.begin(); it != aLines.end(); ++it )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         if( ! access( it->GetBuffer(), F_OK ) )
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             o_rFontPaths.push_back( *it );
345cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
346cdf0e10cSrcweir             fprintf( stderr, "adding fs dir %s\n", it->GetBuffer() );
347cdf0e10cSrcweir #endif
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir #else
351cdf0e10cSrcweir     (void)o_rFontPaths;
352cdf0e10cSrcweir #endif
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 
FillFontPathList(std::list<rtl::OString> & o_rFontPaths)357cdf0e10cSrcweir void X11SalInstance::FillFontPathList( std::list< rtl::OString >& o_rFontPaths )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     Display *pDisplay = GetX11SalData()->GetDisplay()->GetDisplay();
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     DBG_ASSERT( pDisplay, "No Display !" );
362cdf0e10cSrcweir     if( pDisplay )
363cdf0e10cSrcweir     {
364cdf0e10cSrcweir         // get font paths to look for fonts
365cdf0e10cSrcweir         int nPaths = 0, i;
366cdf0e10cSrcweir         char** pPaths = XGetFontPath( pDisplay, &nPaths );
367cdf0e10cSrcweir 
368cdf0e10cSrcweir         bool bServerDirs = false;
369cdf0e10cSrcweir         for( i = 0; i < nPaths; i++ )
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             OString aPath( pPaths[i] );
372cdf0e10cSrcweir             sal_Int32 nPos = 0;
373cdf0e10cSrcweir             if( ! bServerDirs
374cdf0e10cSrcweir                 && ( nPos = aPath.indexOf( ':' ) ) > 0
375cdf0e10cSrcweir                 && ( !aPath.copy(nPos).equals( ":unscaled" ) ) )
376cdf0e10cSrcweir             {
377cdf0e10cSrcweir                 bServerDirs = true;
378cdf0e10cSrcweir                 getServerDirectories( o_rFontPaths );
379cdf0e10cSrcweir             }
380cdf0e10cSrcweir             else
381cdf0e10cSrcweir             {
382cdf0e10cSrcweir                 psp::normPath( aPath );
383cdf0e10cSrcweir                 o_rFontPaths.push_back( aPath );
384cdf0e10cSrcweir             }
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         if( nPaths )
388cdf0e10cSrcweir             XFreeFontPath( pPaths );
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     // insert some standard directories
392cdf0e10cSrcweir     o_rFontPaths.push_back( "/usr/openwin/lib/X11/fonts/TrueType" );
393cdf0e10cSrcweir     o_rFontPaths.push_back( "/usr/openwin/lib/X11/fonts/Type1" );
394cdf0e10cSrcweir     o_rFontPaths.push_back( "/usr/openwin/lib/X11/fonts/Type1/sun" );
395cdf0e10cSrcweir     o_rFontPaths.push_back( "/usr/X11R6/lib/X11/fonts/truetype" );
396cdf0e10cSrcweir     o_rFontPaths.push_back( "/usr/X11R6/lib/X11/fonts/Type1" );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     #ifdef SOLARIS
399cdf0e10cSrcweir     /* cde specials, from /usr/dt/bin/Xsession: here are the good fonts,
400cdf0e10cSrcweir     the OWfontpath file may contain as well multiple lines as a comma
401cdf0e10cSrcweir     separated list of fonts in each line. to make it even more weird
402cdf0e10cSrcweir     environment variables are allowed as well */
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     const char* lang = getenv("LANG");
405cdf0e10cSrcweir     if ( lang != NULL )
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         String aOpenWinDir( String::CreateFromAscii( "/usr/openwin/lib/locale/" ) );
408cdf0e10cSrcweir         aOpenWinDir.AppendAscii( lang );
409cdf0e10cSrcweir         aOpenWinDir.AppendAscii( "/OWfontpath" );
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         SvFileStream aStream( aOpenWinDir, STREAM_READ );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         // TODO: replace environment variables
414cdf0e10cSrcweir         while( aStream.IsOpen() && ! aStream.IsEof() )
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             ByteString aLine;
417cdf0e10cSrcweir             aStream.ReadLine( aLine );
418cdf0e10cSrcweir             // need an OString for normpath
419cdf0e10cSrcweir             OString aNLine( aLine );
420cdf0e10cSrcweir             psp::normPath( aNLine );
421cdf0e10cSrcweir             aLine = aNLine;
422cdf0e10cSrcweir             // try to avoid bad fonts in some cases
423cdf0e10cSrcweir             static bool bAvoid = (strncasecmp( lang, "ar", 2 ) == 0) || (strncasecmp( lang, "he", 2 ) == 0) || strncasecmp( lang, "iw", 2 ) == 0 || (strncasecmp( lang, "hi", 2 ) == 0);
424cdf0e10cSrcweir             if( bAvoid && aLine.Search( "iso_8859" ) != STRING_NOTFOUND )
425cdf0e10cSrcweir                 continue;
426cdf0e10cSrcweir             o_rFontPaths.push_back( aLine );
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir     #endif /* SOLARIS */
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
thisModule()432cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} }
433cdf0e10cSrcweir 
AddToRecentDocumentList(const rtl::OUString & rFileUrl,const rtl::OUString & rMimeType)434cdf0e10cSrcweir void X11SalInstance::AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType)
435cdf0e10cSrcweir {
436cdf0e10cSrcweir     const rtl::OUString SYM_ADD_TO_RECENTLY_USED_FILE_LIST(RTL_CONSTASCII_USTRINGPARAM("add_to_recently_used_file_list"));
437cdf0e10cSrcweir     const rtl::OUString LIB_RECENT_FILE(RTL_CONSTASCII_USTRINGPARAM("librecentfile.so"));
438cdf0e10cSrcweir     typedef void (*PFUNC_ADD_TO_RECENTLY_USED_LIST)(const rtl::OUString&, const rtl::OUString&);
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     PFUNC_ADD_TO_RECENTLY_USED_LIST add_to_recently_used_file_list = 0;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     osl::Module module;
443cdf0e10cSrcweir     module.loadRelative( &thisModule, LIB_RECENT_FILE );
444cdf0e10cSrcweir     if (module.is())
445cdf0e10cSrcweir         add_to_recently_used_file_list = (PFUNC_ADD_TO_RECENTLY_USED_LIST)module.getFunctionSymbol(SYM_ADD_TO_RECENTLY_USED_FILE_LIST);
446cdf0e10cSrcweir     if (add_to_recently_used_file_list)
447cdf0e10cSrcweir         add_to_recently_used_file_list(rFileUrl, rMimeType);
448cdf0e10cSrcweir }
449