1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include "com/sun/star/lang/XServiceInfo.hpp"
28 #include "com/sun/star/util/XStringMapping.hpp"
29 
30 #include "cppuhelper/implbase2.hxx"
31 #include "rtl/ustrbuf.hxx"
32 #include "vcl/svapp.hxx"
33 
34 using ::rtl::OUString;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::util;
38 
39 // -----------------------------------------------------------------------
40 
41 namespace vcl
42 {
43 
44 class StringMirror : public ::cppu::WeakAggImplHelper2< XStringMapping, XServiceInfo >
45 {
46 public:
StringMirror()47     StringMirror()
48     {}
49 
~StringMirror()50     virtual ~StringMirror()
51     {}
52 
53     // XServiceInfo
54     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
55     virtual ::sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException);
56     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
57 
58     // XStringMapping
mapStrings(Sequence<OUString> & io_rStrings)59     virtual sal_Bool SAL_CALL mapStrings( Sequence< OUString >& io_rStrings ) throw (RuntimeException)
60     {
61         sal_Int32 nItems = io_rStrings.getLength();
62         for( sal_Int32 n = 0; n < nItems; n++ )
63         {
64             rtl::OUString& rStr( io_rStrings.getArray()[n] );
65 
66             sal_Int32 nLen = rStr.getLength();
67             rtl::OUStringBuffer aMirror( nLen );
68             for(sal_Int32 i = nLen - 1; i >= 0; i--)
69             {
70                 sal_Unicode cChar = rStr[ i ];
71                 aMirror.append(sal_Unicode(GetMirroredChar(cChar)));
72             }
73             rStr = aMirror.makeStringAndClear();
74         }
75         return sal_True;
76     }
77 };
78 
StringMirror_getSupportedServiceNames()79 Sequence< OUString > StringMirror_getSupportedServiceNames()
80 {
81 	static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.StringMirror" ) );
82 	static Sequence< OUString > aServiceNames( &aServiceName, 1 );
83 	return aServiceNames;
84 }
85 
StringMirror_getImplementationName()86 OUString StringMirror_getImplementationName()
87 {
88 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::StringMirror" ) );
89 }
90 
StringMirror_createInstance(const Reference<XMultiServiceFactory> &)91 Reference< XInterface > SAL_CALL StringMirror_createInstance( const Reference< XMultiServiceFactory >&  )
92 {
93 	return static_cast< ::cppu::OWeakObject * >( new StringMirror );
94 }
95 
96 
97 // XServiceInfo
getImplementationName()98 OUString SAL_CALL StringMirror::getImplementationName() throw (RuntimeException)
99 {
100 	return StringMirror_getImplementationName();
101 }
102 
supportsService(const OUString & i_rServiceName)103 sal_Bool SAL_CALL StringMirror::supportsService( const OUString& i_rServiceName ) throw (RuntimeException)
104 {
105 	Sequence< OUString > aSN( StringMirror_getSupportedServiceNames() );
106 	for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
107 	{
108 		if( aSN[nService] == i_rServiceName )
109 			return sal_True;
110 	}
111 	return sal_False;
112 }
113 
getSupportedServiceNames()114 Sequence< OUString > SAL_CALL StringMirror::getSupportedServiceNames() throw (RuntimeException)
115 {
116 	return StringMirror_getSupportedServiceNames();
117 }
118 
119 } // namespace vcl
120