1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
);
67 rShellSet
.Put( *pI
, nWhichId
);
69 rShellSet
.InvalidateItem( nWhichId
);
72 sal_uInt16
ScViewUtil::GetEffLanguage( ScDocument
* pDoc
, const ScAddress
& rPos
)
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
);
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
);
94 eLnge
= LANGUAGE_ENGLISH_US
;
95 if ( eLnge
== LANGUAGE_SYSTEM
)
96 eLnge
= Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
101 sal_Int32
ScViewUtil::GetTransliterationType( sal_uInt16 nSlotID
)
106 case SID_TRANSLITERATE_SENTENCE_CASE
:
107 nType
= com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE
;
109 case SID_TRANSLITERATE_TITLE_CASE
:
110 nType
= com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE
;
112 case SID_TRANSLITERATE_TOGGLE_CASE
:
113 nType
= com::sun::star::i18n::TransliterationModulesExtra::TOGGLE_CASE
;
115 case SID_TRANSLITERATE_UPPER
:
116 nType
= com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE
;
118 case SID_TRANSLITERATE_LOWER
:
119 nType
= com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE
;
121 case SID_TRANSLITERATE_HALFWIDTH
:
122 nType
= com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH
;
124 case SID_TRANSLITERATE_FULLWIDTH
:
125 nType
= com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH
;
127 case SID_TRANSLITERATE_HIRAGANA
:
128 nType
= com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA
;
130 case SID_TRANSLITERATE_KATAGANA
:
131 nType
= com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA
;
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() )
147 if ( !rSettings
.IsShowAccepted() && rAction
.IsAccepted() && !rAction
.IsRejecting() )
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()) )
159 else if ( !rAction
.GetUser().equals(rSettings
.GetTheAuthorToShow()) )
163 if ( rSettings
.HasComment() )
165 OUStringBuffer
aBuf(rAction
.GetComment());
168 rAction
.GetDescription(aTmp
, &rDocument
);
171 OUString aComStr
= aBuf
.makeStringAndClear();
173 if(!rSettings
.IsValidComment(&aComStr
))
177 if ( rSettings
.HasRange() )
178 if ( !rSettings
.GetTheRangeList().Intersects( rAction
.GetBigRange().MakeRange() ) )
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
)
193 case SvxRedlinDateMode::SINCE
:
194 if ( aDateTime
< rFirst
)
198 case SvxRedlinDateMode::EQUAL
:
199 case SvxRedlinDateMode::BETWEEN
:
200 if ( aDateTime
< rFirst
|| aDateTime
> rLast
)
204 case SvxRedlinDateMode::NOTEQUAL
:
205 if ( aDateTime
>= rFirst
&& aDateTime
<= rLast
)
209 case SvxRedlinDateMode::SAVE
:
211 ScChangeTrack
* pTrack
= rDocument
.GetChangeTrack();
212 if ( !pTrack
|| pTrack
->GetLastSavedActionNumber() >=
213 rAction
.GetActionNumber() )
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
)
240 void ScViewUtil::UnmarkFiltered( ScMarkData
& rMark
, ScDocument
* pDoc
)
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
)
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);
271 if ( bChanged
&& !rMark
.HasAnyMultiMarks() )
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
))
304 void ScViewUtil::HideDisabledSlot( SfxItemSet
& rSet
, SfxBindings
& rBindings
, sal_uInt16 nSlotId
)
306 SvtCJKOptions aCJKOptions
;
307 SvtCTLOptions aCTLOptions
;
308 bool bEnabled
= true;
312 case SID_CHINESE_CONVERSION
:
313 case SID_HANGUL_HANJA_CONVERSION
:
314 bEnabled
= aCJKOptions
.IsAnyEnabled();
317 case SID_TRANSLITERATE_HALFWIDTH
:
318 case SID_TRANSLITERATE_FULLWIDTH
:
319 case SID_TRANSLITERATE_HIRAGANA
:
320 case SID_TRANSLITERATE_KATAGANA
:
321 bEnabled
= aCJKOptions
.IsChangeCaseMapEnabled();
326 case SID_INSERT_ZWNBSP
:
327 case SID_INSERT_ZWSP
:
328 bEnabled
= aCTLOptions
.IsCTLFontEnabled();
332 OSL_FAIL( "ScViewUtil::HideDisabledSlot - unknown slot ID" );
336 rBindings
.SetVisibleState( nSlotId
, bEnabled
);
338 rSet
.DisableItem( nSlotId
);
341 bool ScViewUtil::ExecuteCharMap( const SvxFontItem
& rOldFont
,
342 SfxViewFrame
& rFrame
,
343 SvxFontItem
& rNewFont
,
347 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
359 rString
= pItem
->GetValue();
361 rNewFont
= SvxFontItem( pFontItem
->GetFamily(), pFontItem
->GetFamilyName(), pFontItem
->GetStyleName(), pFontItem
->GetPitch(), pFontItem
->GetCharSet(), rNewFont
.Which() );
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();
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
)
396 PutInOrder( nX1
, nX2
);
397 PutInOrder( nY1
, nY2
);
405 void ScUpdateRect::SetNew( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
)
407 PutInOrder( nX1
, nX2
);
408 PutInOrder( nY1
, nY2
);
416 bool ScUpdateRect::GetDiff( SCCOL
& rX1
, SCROW
& rY1
, SCCOL
& rX2
, SCROW
& rY2
)
418 if ( nNewStartX
== nOldStartX
&& nNewEndX
== nOldEndX
&&
419 nNewStartY
== nOldStartY
&& nNewEndY
== nOldEndY
)
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
);
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */