1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documen6.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "scitems.hxx"
37 #include <svx/scripttypeitem.hxx>
39 #include <com/sun/star/i18n/XBreakIterator.hpp>
40 #include <com/sun/star/i18n/ScriptType.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include "document.hxx"
45 #include "cellform.hxx"
46 #include "patattr.hxx"
47 #include "scrdata.hxx"
48 #include "poolhelp.hxx"
50 using namespace com::sun::star
;
52 #define SC_BREAKITER_SERVICE "com.sun.star.i18n.BreakIterator"
55 // this file is compiled with exceptions enabled
56 // put functions here that need exceptions!
59 // -----------------------------------------------------------------------
61 const uno::Reference
< i18n::XBreakIterator
>& ScDocument::GetBreakIterator()
63 if ( !pScriptTypeData
)
64 pScriptTypeData
= new ScScriptTypeData
;
65 if ( !pScriptTypeData
->xBreakIter
.is() )
67 uno::Reference
< uno::XInterface
> xInterface
= xServiceManager
->createInstance(
68 ::rtl::OUString::createFromAscii( SC_BREAKITER_SERVICE
) );
69 pScriptTypeData
->xBreakIter
= uno::Reference
< i18n::XBreakIterator
>( xInterface
, uno::UNO_QUERY
);
70 DBG_ASSERT( pScriptTypeData
->xBreakIter
.is(), "can't get BreakIterator" );
72 return pScriptTypeData
->xBreakIter
;
75 BOOL
ScDocument::HasStringWeakCharacters( const String
& rString
)
79 uno::Reference
<i18n::XBreakIterator
> xBreakIter
= GetBreakIterator();
80 if ( xBreakIter
.is() )
82 rtl::OUString aText
= rString
;
83 sal_Int32 nLen
= aText
.getLength();
88 sal_Int16 nType
= xBreakIter
->getScriptType( aText
, nPos
);
89 if ( nType
== i18n::ScriptType::WEAK
)
92 nPos
= xBreakIter
->endOfScript( aText
, nPos
, nType
);
94 while ( nPos
>= 0 && nPos
< nLen
);
98 return FALSE
; // none found
101 BYTE
ScDocument::GetStringScriptType( const String
& rString
)
107 uno::Reference
<i18n::XBreakIterator
> xBreakIter
= GetBreakIterator();
108 if ( xBreakIter
.is() )
110 rtl::OUString aText
= rString
;
111 sal_Int32 nLen
= aText
.getLength();
116 sal_Int16 nType
= xBreakIter
->getScriptType( aText
, nPos
);
119 case i18n::ScriptType::LATIN
:
120 nRet
|= SCRIPTTYPE_LATIN
;
122 case i18n::ScriptType::ASIAN
:
123 nRet
|= SCRIPTTYPE_ASIAN
;
125 case i18n::ScriptType::COMPLEX
:
126 nRet
|= SCRIPTTYPE_COMPLEX
;
130 nPos
= xBreakIter
->endOfScript( aText
, nPos
, nType
);
132 while ( nPos
>= 0 && nPos
< nLen
);
138 BYTE
ScDocument::GetCellScriptType( ScBaseCell
* pCell
, ULONG nNumberFormat
)
143 BYTE nStored
= pCell
->GetScriptType();
144 if ( nStored
!= SC_SCRIPTTYPE_UNKNOWN
) // stored value valid?
145 return nStored
; // use stored value
149 ScCellFormat::GetString( pCell
, nNumberFormat
, aStr
, &pColor
, *xPoolHelper
->GetFormTable() );
151 BYTE nRet
= GetStringScriptType( aStr
);
153 pCell
->SetScriptType( nRet
); // store for later calls
158 BYTE
ScDocument::GetScriptType( SCCOL nCol
, SCROW nRow
, SCTAB nTab
, ScBaseCell
* pCell
)
160 // if cell is not passed, take from document
164 pCell
= GetCell( ScAddress( nCol
, nRow
, nTab
) );
169 // if script type is set, don't have to get number formats
171 BYTE nStored
= pCell
->GetScriptType();
172 if ( nStored
!= SC_SCRIPTTYPE_UNKNOWN
) // stored value valid?
173 return nStored
; // use stored value
175 // include number formats from conditional formatting
177 const ScPatternAttr
* pPattern
= GetPattern( nCol
, nRow
, nTab
);
178 if (!pPattern
) return 0;
179 const SfxItemSet
* pCondSet
= NULL
;
180 if ( ((const SfxUInt32Item
&)pPattern
->GetItem(ATTR_CONDITIONAL
)).GetValue() )
181 pCondSet
= GetCondResult( nCol
, nRow
, nTab
);
183 ULONG nFormat
= pPattern
->GetNumberFormat( xPoolHelper
->GetFormTable(), pCondSet
);
184 return GetCellScriptType( pCell
, nFormat
);