xref: /trunk/main/sw/inc/breakit.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _BREAKIT_HXX
29*cdf0e10cSrcweir #define _BREAKIT_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/solar.h>
32*cdf0e10cSrcweir #include <i18npool/lang.h>
33*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/i18n/ForbiddenCharacters.hdl>
38*cdf0e10cSrcweir #include <swdllapi.h>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir class String;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /*************************************************************************
43*cdf0e10cSrcweir  *                      class SwBreakIt
44*cdf0e10cSrcweir  *************************************************************************/
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir class SW_DLLPUBLIC SwBreakIt
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMSF;
50*cdf0e10cSrcweir     mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > xBreak;
51*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::i18n::XScriptTypeDetector > xCTLDetect;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     com::sun::star::lang::Locale * m_pLocale;
55*cdf0e10cSrcweir     com::sun::star::i18n::ForbiddenCharacters * m_pForbidden;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     LanguageType aLast;          // language of the current locale
58*cdf0e10cSrcweir     LanguageType aForbiddenLang; // language of the current forbiddenChar struct
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     void _GetLocale( const LanguageType aLang );
61*cdf0e10cSrcweir     void _GetForbidden( const LanguageType  aLang );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     void createBreakIterator() const;
64*cdf0e10cSrcweir     void createScriptTypeDetector();
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     // forbidden and not implemented.
67*cdf0e10cSrcweir     SwBreakIt();
68*cdf0e10cSrcweir     SwBreakIt( const SwBreakIt &);
69*cdf0e10cSrcweir     SwBreakIt & operator= ( const SwBreakIt &);
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     // private (see @ _Create, _Delete).
72*cdf0e10cSrcweir     explicit SwBreakIt(
73*cdf0e10cSrcweir         const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rxMSF);
74*cdf0e10cSrcweir     ~SwBreakIt();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir public:
77*cdf0e10cSrcweir     // private (see @ source/core/bastyp/init.cxx).
78*cdf0e10cSrcweir     static void _Create(
79*cdf0e10cSrcweir         const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rxMSF);
80*cdf0e10cSrcweir     static void _Delete();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir public:
83*cdf0e10cSrcweir     static SwBreakIt * Get();
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > GetBreakIter()
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         createBreakIterator();
88*cdf0e10cSrcweir         return xBreak;
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::i18n::XScriptTypeDetector > GetScriptTypeDetector()
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         createScriptTypeDetector();
94*cdf0e10cSrcweir         return xCTLDetect;
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     const com::sun::star::lang::Locale& GetLocale( const LanguageType aLang )
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         if( !m_pLocale || aLast != aLang )
100*cdf0e10cSrcweir             _GetLocale( aLang );
101*cdf0e10cSrcweir         return *m_pLocale;
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     const com::sun::star::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
105*cdf0e10cSrcweir     {
106*cdf0e10cSrcweir         if( !m_pForbidden || aForbiddenLang != aLang )
107*cdf0e10cSrcweir             _GetForbidden( aLang );
108*cdf0e10cSrcweir         return *m_pForbidden;
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     sal_uInt16 GetRealScriptOfText( const String& rTxt, xub_StrLen nPos ) const;
112*cdf0e10cSrcweir     sal_uInt16 GetAllScriptsOfText( const String& rTxt ) const;
113*cdf0e10cSrcweir };
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir #define SW_BREAKITER()  SwBreakIt::Get()
116*cdf0e10cSrcweir #define SW_XBREAKITER() SW_BREAKITER()->GetBreakIter()
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // @@@ backward compatibility @@@
119*cdf0e10cSrcweir SW_DLLPUBLIC extern SwBreakIt* pBreakIt;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir #endif
122*cdf0e10cSrcweir 
123