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 #ifndef _MACSPELLIMP_H_
25 #define _MACSPELLIMP_H_
26 
27 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
28 #include <cppuhelper/implbase1.hxx>	// helper for implementations
29 #include <cppuhelper/implbase6.hxx>	// helper for implementations
30 
31 #ifdef MACOSX
32 #include <premac.h>
33 #include <Carbon/Carbon.h>
34 #include <CoreFoundation/CoreFoundation.h>
35 #import <Cocoa/Cocoa.h>
36 #import <Foundation/Foundation.h>
37 #include <postmac.h>
38 #endif
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <com/sun/star/lang/XServiceDisplayName.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/PropertyValues.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
46 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
47 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
48 #include <tools/table.hxx>
49 
50 #include <linguistic/misc.hxx>
51 #include <linguistic/lngprophelp.hxx>
52 
53 #include <lingutil.hxx>
54 
55 using namespace ::rtl;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::linguistic2;
60 
61 
62 ///////////////////////////////////////////////////////////////////////////
63 
64 
65 class MacSpellChecker :
66 	public cppu::WeakImplHelper6
67 	<
68 		XSpellChecker,
69 		XLinguServiceEventBroadcaster,
70 		XInitialization,
71 		XComponent,
72 		XServiceInfo,
73 		XServiceDisplayName
74 	>
75 {
76     Sequence< Locale >      aSuppLocales;
77     rtl_TextEncoding *      aDEncs;
78     Locale *                aDLocs;
79     OUString *              aDNames;
80     sal_Int32               numdict;
81     NSSpellChecker *        macSpell;
82     int                     macTag;   //unique tag for this doc
83 
84 	::cppu::OInterfaceContainerHelper		aEvtListeners;
85 	Reference< XPropertyChangeListener >	xPropHelper;
86     linguistic::PropertyHelper_Spell *      pPropHelper;
87 	sal_Bool									bDisposing;
88 
89 	// disallow copy-constructor and assignment-operator for now
90 	MacSpellChecker(const MacSpellChecker &);
91 	MacSpellChecker & operator = (const MacSpellChecker &);
92 
93     linguistic::PropertyHelper_Spell &  GetPropHelper_Impl();
GetPropHelper()94     linguistic::PropertyHelper_Spell &  GetPropHelper()
95 	{
96 		return pPropHelper ? *pPropHelper : GetPropHelper_Impl();
97 	}
98 
99 	sal_Int16	GetSpellFailure( const OUString &rWord, const Locale &rLocale );
100     Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale );
101 
102 public:
103 	MacSpellChecker();
104 	virtual ~MacSpellChecker();
105 
106 	// XSupportedLocales (for XSpellChecker)
107     virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
108     virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
109 
110 	// XSpellChecker
111     virtual sal_Bool SAL_CALL isValid( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
112     virtual Reference< XSpellAlternatives > SAL_CALL spell( const OUString& rWord, const Locale& rLocale, const PropertyValues& rProperties ) throw(IllegalArgumentException, RuntimeException);
113 
114     // XLinguServiceEventBroadcaster
115     virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
116     virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
117 
118 	// XServiceDisplayName
119     virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
120 
121 	// XInitialization
122     virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
123 
124 	// XComponent
125     virtual void SAL_CALL dispose() throw(RuntimeException);
126     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
127     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
128 
129 	// XServiceInfo
130     virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
131     virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
132     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
133 
134 
135     static inline OUString  getImplementationName_Static() throw();
136     static Sequence< OUString > getSupportedServiceNames_Static() throw();
137 };
138 
getImplementationName_Static()139 inline OUString MacSpellChecker::getImplementationName_Static() throw()
140 {
141 	return A2OU( "org.openoffice.lingu.MacOSXSpellChecker" );
142 }
143 
144 
145 
146 ///////////////////////////////////////////////////////////////////////////
147 
148 #endif
149 
150