fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / documen6.cxx
blob8b6009df4b0521563da46c825ee5afbca235e019
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
21 #include <editeng/scripttypeitem.hxx>
23 #include <com/sun/star/i18n/BreakIterator.hpp>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <comphelper/processfactory.hxx>
28 #include "document.hxx"
29 #include "cellform.hxx"
30 #include "patattr.hxx"
31 #include "scrdata.hxx"
32 #include "poolhelp.hxx"
33 #include "attrib.hxx"
34 #include "globalnames.hxx"
35 #include "columnspanset.hxx"
36 #include "table.hxx"
38 using namespace com::sun::star;
40 // this file is compiled with exceptions enabled
41 // put functions here that need exceptions!
43 const uno::Reference< i18n::XBreakIterator >& ScDocument::GetBreakIterator()
45 if ( !pScriptTypeData )
46 pScriptTypeData = new ScScriptTypeData;
47 if ( !pScriptTypeData->xBreakIter.is() )
49 pScriptTypeData->xBreakIter = i18n::BreakIterator::create( comphelper::getProcessComponentContext() );
51 return pScriptTypeData->xBreakIter;
54 bool ScDocument::HasStringWeakCharacters( const OUString& rString )
56 if (!rString.isEmpty())
58 uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
59 if ( xBreakIter.is() )
61 sal_Int32 nLen = rString.getLength();
63 sal_Int32 nPos = 0;
66 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
67 if ( nType == i18n::ScriptType::WEAK )
68 return true; // found
70 nPos = xBreakIter->endOfScript( rString, nPos, nType );
72 while ( nPos >= 0 && nPos < nLen );
76 return false; // none found
79 SvtScriptType ScDocument::GetStringScriptType( const OUString& rString )
81 SvtScriptType nRet = SvtScriptType::NONE;
82 if (!rString.isEmpty())
84 uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
85 if ( xBreakIter.is() )
87 sal_Int32 nLen = rString.getLength();
89 sal_Int32 nPos = 0;
92 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
93 switch ( nType )
95 case i18n::ScriptType::LATIN:
96 nRet |= SvtScriptType::LATIN;
97 break;
98 case i18n::ScriptType::ASIAN:
99 nRet |= SvtScriptType::ASIAN;
100 break;
101 case i18n::ScriptType::COMPLEX:
102 nRet |= SvtScriptType::COMPLEX;
103 break;
104 // WEAK is ignored
106 nPos = xBreakIter->endOfScript( rString, nPos, nType );
108 while ( nPos >= 0 && nPos < nLen );
111 return nRet;
114 SvtScriptType ScDocument::GetCellScriptType( const ScAddress& rPos, sal_uLong nNumberFormat )
116 SvtScriptType nStored = GetScriptType(rPos);
117 if ( nStored != SvtScriptType::UNKNOWN ) // stored value valid?
118 return nStored; // use stored value
120 Color* pColor;
121 OUString aStr = ScCellFormat::GetString(*this, rPos, nNumberFormat, &pColor, *xPoolHelper->GetFormTable());
123 SvtScriptType nRet = GetStringScriptType( aStr );
125 SetScriptType(rPos, nRet); // store for later calls
127 return nRet;
130 SvtScriptType ScDocument::GetScriptType( SCCOL nCol, SCROW nRow, SCTAB nTab )
132 // if script type is set, don't have to get number formats
134 ScAddress aPos(nCol, nRow, nTab);
135 SvtScriptType nStored = GetScriptType(aPos);
136 if ( nStored != SvtScriptType::UNKNOWN ) // stored value valid?
137 return nStored; // use stored value
139 // include number formats from conditional formatting
141 const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
142 if (!pPattern) return SvtScriptType::NONE;
143 const SfxItemSet* pCondSet = NULL;
144 if ( !static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData().empty() )
145 pCondSet = GetCondResult( nCol, nRow, nTab );
147 sal_uLong nFormat = pPattern->GetNumberFormat( xPoolHelper->GetFormTable(), pCondSet );
149 return GetCellScriptType(aPos, nFormat);
152 namespace {
154 class ScriptTypeAggregator : public sc::ColumnSpanSet::Action
156 ScDocument& mrDoc;
157 sc::ColumnBlockPosition maBlockPos;
158 SvtScriptType mnScriptType;
160 public:
161 ScriptTypeAggregator(ScDocument& rDoc) : mrDoc(rDoc), mnScriptType(SvtScriptType::NONE) {}
163 virtual void startColumn(SCTAB nTab, SCCOL nCol) SAL_OVERRIDE
165 mrDoc.InitColumnBlockPosition(maBlockPos, nTab, nCol);
168 virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal) SAL_OVERRIDE
170 if (!bVal)
171 return;
173 mnScriptType |= mrDoc.GetRangeScriptType(maBlockPos, rPos, nLength);
176 SvtScriptType getScriptType() const { return mnScriptType; }
181 SvtScriptType ScDocument::GetRangeScriptType(
182 sc::ColumnBlockPosition& rBlockPos, const ScAddress& rPos, SCROW nLength )
184 if (!TableExists(rPos.Tab()))
185 return SvtScriptType::NONE;
187 return maTabs[rPos.Tab()]->GetRangeScriptType(rBlockPos, rPos.Col(), rPos.Row(), rPos.Row()+nLength-1);
190 SvtScriptType ScDocument::GetRangeScriptType( const ScRangeList& rRanges )
192 sc::ColumnSpanSet aSet(false);
193 for (size_t i = 0, n = rRanges.size(); i < n; ++i)
195 const ScRange& rRange = *rRanges[i];
196 SCTAB nTab = rRange.aStart.Tab();
197 SCROW nRow1 = rRange.aStart.Row();
198 SCROW nRow2 = rRange.aEnd.Row();
199 for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
200 aSet.set(nTab, nCol, nRow1, nRow2, true);
203 ScriptTypeAggregator aAction(*this);
204 aSet.executeAction(aAction);
205 return aAction.getScriptType();
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */