fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / viewutil.cxx
blobb70211e4039543317332d13ea7d4affb48cc2e60
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 <sfx2/bindings.hxx>
22 #include <sfx2/viewsh.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <editeng/fontitem.hxx>
25 #include <editeng/langitem.hxx>
26 #include <editeng/scripttypeitem.hxx>
27 #include <svl/itempool.hxx>
28 #include <svl/itemset.hxx>
29 #include <svl/cjkoptions.hxx>
30 #include <svl/ctloptions.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <vcl/wrkwin.hxx>
34 #include <vcl/settings.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <svl/stritem.hxx>
38 #include <svl/eitem.hxx>
40 #include <com/sun/star/i18n/TransliterationModules.hpp>
41 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
43 #include "viewutil.hxx"
44 #include "global.hxx"
45 #include "chgtrack.hxx"
46 #include "chgviset.hxx"
47 #include "markdata.hxx"
48 #include "document.hxx"
50 #include <svx/svxdlg.hxx>
51 #include <svx/dialogs.hrc>
52 #include <boost/scoped_ptr.hpp>
54 void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSet,
55 sal_uInt16 nWhichId, SvtScriptType nScript )
57 // take the effective item from rCoreSet according to nScript
58 // and put in rShellSet under the (base) nWhichId
60 SfxItemPool& rPool = *rShellSet.GetPool();
61 SvxScriptSetItem aSetItem( rPool.GetSlotId(nWhichId), rPool );
62 // use PutExtended with eDefaultAs = SfxItemState::SET, so defaults from rCoreSet
63 // (document pool) are read and put into rShellSet (MessagePool)
64 aSetItem.GetItemSet().PutExtended( rCoreSet, SfxItemState::DONTCARE, SfxItemState::SET );
65 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
66 if (pI)
67 rShellSet.Put( *pI, nWhichId );
68 else
69 rShellSet.InvalidateItem( nWhichId );
72 sal_uInt16 ScViewUtil::GetEffLanguage( ScDocument* pDoc, const ScAddress& rPos )
74 // used for thesaurus
76 SvtScriptType nScript = pDoc->GetScriptType(rPos.Col(), rPos.Row(), rPos.Tab());
77 sal_uInt16 nWhich = ( nScript == SvtScriptType::ASIAN ) ? ATTR_CJK_FONT_LANGUAGE :
78 ( ( nScript == SvtScriptType::COMPLEX ) ? ATTR_CTL_FONT_LANGUAGE : ATTR_FONT_LANGUAGE );
79 const SfxPoolItem* pItem = pDoc->GetAttr( rPos.Col(), rPos.Row(), rPos.Tab(), nWhich);
80 const SvxLanguageItem* pLangIt = PTR_CAST( SvxLanguageItem, pItem );
81 LanguageType eLnge;
82 if (pLangIt)
84 eLnge = (LanguageType) pLangIt->GetValue();
85 if (eLnge == LANGUAGE_DONTKNOW) //! can this happen?
87 LanguageType eLatin, eCjk, eCtl;
88 pDoc->GetLanguage( eLatin, eCjk, eCtl );
89 eLnge = ( nScript == SvtScriptType::ASIAN ) ? eCjk :
90 ( ( nScript == SvtScriptType::COMPLEX ) ? eCtl : eLatin );
93 else
94 eLnge = LANGUAGE_ENGLISH_US;
95 if ( eLnge == LANGUAGE_SYSTEM )
96 eLnge = Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
98 return eLnge;
101 sal_Int32 ScViewUtil::GetTransliterationType( sal_uInt16 nSlotID )
103 sal_Int32 nType = 0;
104 switch ( nSlotID )
106 case SID_TRANSLITERATE_SENTENCE_CASE:
107 nType = com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE;
108 break;
109 case SID_TRANSLITERATE_TITLE_CASE:
110 nType = com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE;
111 break;
112 case SID_TRANSLITERATE_TOGGLE_CASE:
113 nType = com::sun::star::i18n::TransliterationModulesExtra::TOGGLE_CASE;
114 break;
115 case SID_TRANSLITERATE_UPPER:
116 nType = com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE;
117 break;
118 case SID_TRANSLITERATE_LOWER:
119 nType = com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE;
120 break;
121 case SID_TRANSLITERATE_HALFWIDTH:
122 nType = com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH;
123 break;
124 case SID_TRANSLITERATE_FULLWIDTH:
125 nType = com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH;
126 break;
127 case SID_TRANSLITERATE_HIRAGANA:
128 nType = com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA;
129 break;
130 case SID_TRANSLITERATE_KATAGANA:
131 nType = com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA;
132 break;
134 return nType;
137 bool ScViewUtil::IsActionShown( const ScChangeAction& rAction,
138 const ScChangeViewSettings& rSettings,
139 ScDocument& rDocument )
141 // discarded are displayed as inverted accepted action, because of this
142 // order of ShowRejected/ShowAccepted is important
144 if ( !rSettings.IsShowRejected() && rAction.IsRejecting() )
145 return false;
147 if ( !rSettings.IsShowAccepted() && rAction.IsAccepted() && !rAction.IsRejecting() )
148 return false;
150 if ( rSettings.HasAuthor() )
152 if ( rSettings.IsEveryoneButMe() )
154 // GetUser() at ChangeTrack is the current user
155 ScChangeTrack* pTrack = rDocument.GetChangeTrack();
156 if ( !pTrack || rAction.GetUser().equals(pTrack->GetUser()) )
157 return false;
159 else if ( !rAction.GetUser().equals(rSettings.GetTheAuthorToShow()) )
160 return false;
163 if ( rSettings.HasComment() )
165 OUStringBuffer aBuf(rAction.GetComment());
166 aBuf.append(" (");
167 OUString aTmp;
168 rAction.GetDescription(aTmp, &rDocument);
169 aBuf.append(aTmp);
170 aBuf.append(')');
171 OUString aComStr = aBuf.makeStringAndClear();
173 if(!rSettings.IsValidComment(&aComStr))
174 return false;
177 if ( rSettings.HasRange() )
178 if ( !rSettings.GetTheRangeList().Intersects( rAction.GetBigRange().MakeRange() ) )
179 return false;
181 if (rSettings.HasDate() && rSettings.GetTheDateMode() != SvxRedlinDateMode::NONE)
183 DateTime aDateTime = rAction.GetDateTime();
184 const DateTime& rFirst = rSettings.GetTheFirstDateTime();
185 const DateTime& rLast = rSettings.GetTheLastDateTime();
186 switch ( rSettings.GetTheDateMode() )
187 { // corresponds with ScHighlightChgDlg::OKBtnHdl
188 case SvxRedlinDateMode::BEFORE:
189 if ( aDateTime > rFirst )
190 return false;
191 break;
193 case SvxRedlinDateMode::SINCE:
194 if ( aDateTime < rFirst )
195 return false;
196 break;
198 case SvxRedlinDateMode::EQUAL:
199 case SvxRedlinDateMode::BETWEEN:
200 if ( aDateTime < rFirst || aDateTime > rLast )
201 return false;
202 break;
204 case SvxRedlinDateMode::NOTEQUAL:
205 if ( aDateTime >= rFirst && aDateTime <= rLast )
206 return false;
207 break;
209 case SvxRedlinDateMode::SAVE:
211 ScChangeTrack* pTrack = rDocument.GetChangeTrack();
212 if ( !pTrack || pTrack->GetLastSavedActionNumber() >=
213 rAction.GetActionNumber() )
214 return false;
216 break;
218 default:
220 // added to avoid warnings
225 if ( rSettings.HasActionRange() )
227 sal_uLong nAction = rAction.GetActionNumber();
228 sal_uLong nFirstAction;
229 sal_uLong nLastAction;
230 rSettings.GetTheActionRange( nFirstAction, nLastAction );
231 if ( nAction < nFirstAction || nAction > nLastAction )
233 return false;
237 return true;
240 void ScViewUtil::UnmarkFiltered( ScMarkData& rMark, ScDocument* pDoc )
242 rMark.MarkToMulti();
244 ScRange aMultiArea;
245 rMark.GetMultiMarkArea( aMultiArea );
246 SCCOL nStartCol = aMultiArea.aStart.Col();
247 SCROW nStartRow = aMultiArea.aStart.Row();
248 SCCOL nEndCol = aMultiArea.aEnd.Col();
249 SCROW nEndRow = aMultiArea.aEnd.Row();
251 bool bChanged = false;
252 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
253 for (; itr != itrEnd; ++itr)
255 SCTAB nTab = *itr;
256 for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
258 SCROW nLastRow = nRow;
259 if (pDoc->RowFiltered(nRow, nTab, NULL, &nLastRow))
261 // use nStartCol/nEndCol, so the multi mark area isn't extended to all columns
262 // (visible in repaint for indentation)
263 rMark.SetMultiMarkArea(
264 ScRange(nStartCol, nRow, nTab, nEndCol, nLastRow, nTab), false);
265 bChanged = true;
266 nRow = nLastRow;
271 if ( bChanged && !rMark.HasAnyMultiMarks() )
272 rMark.ResetMark();
274 rMark.MarkToSimple();
277 bool ScViewUtil::FitToUnfilteredRows( ScRange & rRange, ScDocument * pDoc, size_t nRows )
279 SCTAB nTab = rRange.aStart.Tab();
280 bool bOneTabOnly = (nTab == rRange.aEnd.Tab());
281 // Always fit the range on its first sheet.
282 OSL_ENSURE( bOneTabOnly, "ScViewUtil::ExtendToUnfilteredRows: works only on one sheet");
283 SCROW nStartRow = rRange.aStart.Row();
284 SCROW nLastRow = pDoc->LastNonFilteredRow(nStartRow, MAXROW, nTab);
285 if (ValidRow(nLastRow))
286 rRange.aEnd.SetRow(nLastRow);
287 SCROW nCount = pDoc->CountNonFilteredRows(nStartRow, MAXROW, nTab);
288 return static_cast<size_t>(nCount) == nRows && bOneTabOnly;
291 bool ScViewUtil::HasFiltered( const ScRange& rRange, ScDocument* pDoc )
293 SCROW nStartRow = rRange.aStart.Row();
294 SCROW nEndRow = rRange.aEnd.Row();
295 for (SCTAB nTab=rRange.aStart.Tab(); nTab<=rRange.aEnd.Tab(); nTab++)
297 if (pDoc->HasFilteredRows(nStartRow, nEndRow, nTab))
298 return true;
301 return false;
304 void ScViewUtil::HideDisabledSlot( SfxItemSet& rSet, SfxBindings& rBindings, sal_uInt16 nSlotId )
306 SvtCJKOptions aCJKOptions;
307 SvtCTLOptions aCTLOptions;
308 bool bEnabled = true;
310 switch( nSlotId )
312 case SID_CHINESE_CONVERSION:
313 case SID_HANGUL_HANJA_CONVERSION:
314 bEnabled = aCJKOptions.IsAnyEnabled();
315 break;
317 case SID_TRANSLITERATE_HALFWIDTH:
318 case SID_TRANSLITERATE_FULLWIDTH:
319 case SID_TRANSLITERATE_HIRAGANA:
320 case SID_TRANSLITERATE_KATAGANA:
321 bEnabled = aCJKOptions.IsChangeCaseMapEnabled();
322 break;
324 case SID_INSERT_RLM:
325 case SID_INSERT_LRM:
326 case SID_INSERT_ZWNBSP:
327 case SID_INSERT_ZWSP:
328 bEnabled = aCTLOptions.IsCTLFontEnabled();
329 break;
331 default:
332 OSL_FAIL( "ScViewUtil::HideDisabledSlot - unknown slot ID" );
333 return;
336 rBindings.SetVisibleState( nSlotId, bEnabled );
337 if( !bEnabled )
338 rSet.DisableItem( nSlotId );
341 bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
342 SfxViewFrame& rFrame,
343 SvxFontItem& rNewFont,
344 OUString& rString )
346 bool bRet = false;
347 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
348 if(pFact)
350 SfxAllItemSet aSet( rFrame.GetObjectShell()->GetPool() );
351 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
352 aSet.Put( SvxFontItem( rOldFont.GetFamily(), rOldFont.GetFamilyName(), rOldFont.GetStyleName(), rOldFont.GetPitch(), rOldFont.GetCharSet(), aSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT ) ) );
353 boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( &rFrame.GetWindow(), aSet, rFrame.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
354 if ( pDlg->Execute() == RET_OK )
356 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
357 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
358 if ( pItem )
359 rString = pItem->GetValue();
360 if ( pFontItem )
361 rNewFont = SvxFontItem( pFontItem->GetFamily(), pFontItem->GetFamilyName(), pFontItem->GetStyleName(), pFontItem->GetPitch(), pFontItem->GetCharSet(), rNewFont.Which() );
362 bRet = true;
365 return bRet;
368 bool ScViewUtil::IsFullScreen( SfxViewShell& rViewShell )
370 SfxBindings& rBindings = rViewShell.GetViewFrame()->GetBindings();
371 SfxPoolItem* pItem = 0;
372 bool bIsFullScreen = false;
374 if (rBindings.QueryState( SID_WIN_FULLSCREEN, pItem ) >= SfxItemState::DEFAULT)
375 bIsFullScreen = static_cast< SfxBoolItem* >( pItem )->GetValue();
376 delete pItem;
378 return bIsFullScreen;
381 void ScViewUtil::SetFullScreen( SfxViewShell& rViewShell, bool bSet )
383 if( IsFullScreen( rViewShell ) != bSet )
385 SfxBoolItem aItem( SID_WIN_FULLSCREEN, bSet );
386 rViewShell.GetDispatcher()->Execute( SID_WIN_FULLSCREEN, SfxCallMode::RECORD, &aItem, 0L );
390 ScUpdateRect::ScUpdateRect( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
391 : nNewStartX(0)
392 , nNewStartY(0)
393 , nNewEndX(0)
394 , nNewEndY(0)
396 PutInOrder( nX1, nX2 );
397 PutInOrder( nY1, nY2 );
399 nOldStartX = nX1;
400 nOldStartY = nY1;
401 nOldEndX = nX2;
402 nOldEndY = nY2;
405 void ScUpdateRect::SetNew( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
407 PutInOrder( nX1, nX2 );
408 PutInOrder( nY1, nY2 );
410 nNewStartX = nX1;
411 nNewStartY = nY1;
412 nNewEndX = nX2;
413 nNewEndY = nY2;
416 bool ScUpdateRect::GetDiff( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
418 if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX &&
419 nNewStartY == nOldStartY && nNewEndY == nOldEndY )
421 rX1 = nNewStartX;
422 rY1 = nNewStartY;
423 rX2 = nNewStartX;
424 rY2 = nNewStartY;
425 return false;
428 rX1 = std::min(nNewStartX,nOldStartX);
429 rY1 = std::min(nNewStartY,nOldStartY);
430 rX2 = std::max(nNewEndX,nOldEndX);
431 rY2 = std::max(nNewEndY,nOldEndY);
433 if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX )
435 if ( nNewStartY == nOldStartY )
437 rY1 = std::min( nNewEndY, nOldEndY );
438 rY2 = std::max( nNewEndY, nOldEndY );
440 else if ( nNewEndY == nOldEndY )
442 rY1 = std::min( nNewStartY, nOldStartY );
443 rY2 = std::max( nNewStartY, nOldStartY );
446 else if ( nNewStartY == nOldStartY && nNewEndY == nOldEndY )
448 if ( nNewStartX == nOldStartX )
450 rX1 = std::min( nNewEndX, nOldEndX );
451 rX2 = std::max( nNewEndX, nOldEndX );
453 else if ( nNewEndX == nOldEndX )
455 rX1 = std::min( nNewStartX, nOldStartX );
456 rX2 = std::max( nNewStartX, nOldStartX );
460 return true;
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */