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