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 <sfx2/request.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/eitem.hxx>
39 #include <com/sun/star/i18n/TransliterationModules.hpp>
40 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
42 #include "viewutil.hxx"
44 #include "chgtrack.hxx"
45 #include "chgviset.hxx"
46 #include "markdata.hxx"
47 #include "document.hxx"
49 #include <svx/svxdlg.hxx>
50 #include <svx/dialogs.hrc>
53 void ScViewUtil::PutItemScript( SfxItemSet
& rShellSet
, const SfxItemSet
& rCoreSet
,
54 sal_uInt16 nWhichId
, sal_uInt16 nScript
)
56 // take the effective item from rCoreSet according to nScript
57 // and put in rShellSet under the (base) nWhichId
59 SfxItemPool
& rPool
= *rShellSet
.GetPool();
60 SvxScriptSetItem
aSetItem( rPool
.GetSlotId(nWhichId
), rPool
);
61 // use PutExtended with eDefaultAs = SFX_ITEM_SET, so defaults from rCoreSet
62 // (document pool) are read and put into rShellSet (MessagePool)
63 aSetItem
.GetItemSet().PutExtended( rCoreSet
, SFX_ITEM_DONTCARE
, SFX_ITEM_SET
);
64 const SfxPoolItem
* pI
= aSetItem
.GetItemOfScript( nScript
);
66 rShellSet
.Put( *pI
, nWhichId
);
68 rShellSet
.InvalidateItem( nWhichId
);
71 sal_uInt16
ScViewUtil::GetEffLanguage( ScDocument
* pDoc
, const ScAddress
& rPos
)
75 sal_uInt8 nScript
= pDoc
->GetScriptType(rPos
.Col(), rPos
.Row(), rPos
.Tab());
76 sal_uInt16 nWhich
= ( nScript
== SCRIPTTYPE_ASIAN
) ? ATTR_CJK_FONT_LANGUAGE
:
77 ( ( nScript
== SCRIPTTYPE_COMPLEX
) ? ATTR_CTL_FONT_LANGUAGE
: ATTR_FONT_LANGUAGE
);
78 const SfxPoolItem
* pItem
= pDoc
->GetAttr( rPos
.Col(), rPos
.Row(), rPos
.Tab(), nWhich
);
79 SvxLanguageItem
* pLangIt
= PTR_CAST( SvxLanguageItem
, pItem
);
83 eLnge
= (LanguageType
) pLangIt
->GetValue();
84 if (eLnge
== LANGUAGE_DONTKNOW
) //! can this happen?
86 LanguageType eLatin
, eCjk
, eCtl
;
87 pDoc
->GetLanguage( eLatin
, eCjk
, eCtl
);
88 eLnge
= ( nScript
== SCRIPTTYPE_ASIAN
) ? eCjk
:
89 ( ( nScript
== SCRIPTTYPE_COMPLEX
) ? eCtl
: eLatin
);
93 eLnge
= LANGUAGE_ENGLISH_US
;
94 if ( eLnge
== LANGUAGE_SYSTEM
)
95 eLnge
= Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
100 sal_Int32
ScViewUtil::GetTransliterationType( sal_uInt16 nSlotID
)
105 case SID_TRANSLITERATE_SENTENCE_CASE
:
106 nType
= com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE
;
108 case SID_TRANSLITERATE_TITLE_CASE
:
109 nType
= com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE
;
111 case SID_TRANSLITERATE_TOGGLE_CASE
:
112 nType
= com::sun::star::i18n::TransliterationModulesExtra::TOGGLE_CASE
;
114 case SID_TRANSLITERATE_UPPER
:
115 nType
= com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE
;
117 case SID_TRANSLITERATE_LOWER
:
118 nType
= com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE
;
120 case SID_TRANSLITERATE_HALFWIDTH
:
121 nType
= com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH
;
123 case SID_TRANSLITERATE_FULLWIDTH
:
124 nType
= com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH
;
126 case SID_TRANSLITERATE_HIRAGANA
:
127 nType
= com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA
;
129 case SID_TRANSLITERATE_KATAGANA
:
130 nType
= com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA
;
136 sal_Bool
ScViewUtil::IsActionShown( const ScChangeAction
& rAction
,
137 const ScChangeViewSettings
& rSettings
,
138 ScDocument
& rDocument
)
140 // discarded are displayed as inverted accepted action, because of this
141 // order of ShowRejected/ShowAccepted is important
143 if ( !rSettings
.IsShowRejected() && rAction
.IsRejecting() )
146 if ( !rSettings
.IsShowAccepted() && rAction
.IsAccepted() && !rAction
.IsRejecting() )
149 if ( rSettings
.HasAuthor() )
151 if ( rSettings
.IsEveryoneButMe() )
153 // GetUser() at ChangeTrack is the current user
154 ScChangeTrack
* pTrack
= rDocument
.GetChangeTrack();
155 if ( !pTrack
|| rAction
.GetUser().equals(pTrack
->GetUser()) )
158 else if ( !rAction
.GetUser().equals(rSettings
.GetTheAuthorToShow()) )
162 if ( rSettings
.HasComment() )
164 OUStringBuffer
aBuf(rAction
.GetComment());
165 aBuf
.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
167 rAction
.GetDescription(aTmp
, &rDocument
);
169 aBuf
.append(sal_Unicode(')'));
170 OUString aComStr
= aBuf
.makeStringAndClear();
172 if(!rSettings
.IsValidComment(&aComStr
))
176 if ( rSettings
.HasRange() )
177 if ( !rSettings
.GetTheRangeList().Intersects( rAction
.GetBigRange().MakeRange() ) )
180 if ( rSettings
.HasDate() && rSettings
.GetTheDateMode() != SCDM_NO_DATEMODE
)
182 DateTime aDateTime
= rAction
.GetDateTime();
183 const DateTime
& rFirst
= rSettings
.GetTheFirstDateTime();
184 const DateTime
& rLast
= rSettings
.GetTheLastDateTime();
185 switch ( rSettings
.GetTheDateMode() )
186 { // corresponds with ScHighlightChgDlg::OKBtnHdl
187 case SCDM_DATE_BEFORE
:
188 if ( aDateTime
> rFirst
)
192 case SCDM_DATE_SINCE
:
193 if ( aDateTime
< rFirst
)
197 case SCDM_DATE_EQUAL
:
198 case SCDM_DATE_BETWEEN
:
199 if ( aDateTime
< rFirst
|| aDateTime
> rLast
)
203 case SCDM_DATE_NOTEQUAL
:
204 if ( aDateTime
>= rFirst
&& aDateTime
<= rLast
)
210 ScChangeTrack
* pTrack
= rDocument
.GetChangeTrack();
211 if ( !pTrack
|| pTrack
->GetLastSavedActionNumber() >=
212 rAction
.GetActionNumber() )
219 // added to avoid warnings
224 if ( rSettings
.HasActionRange() )
226 sal_uLong nAction
= rAction
.GetActionNumber();
227 sal_uLong nFirstAction
;
228 sal_uLong nLastAction
;
229 rSettings
.GetTheActionRange( nFirstAction
, nLastAction
);
230 if ( nAction
< nFirstAction
|| nAction
> nLastAction
)
239 void ScViewUtil::UnmarkFiltered( ScMarkData
& rMark
, ScDocument
* pDoc
)
244 rMark
.GetMultiMarkArea( aMultiArea
);
245 SCCOL nStartCol
= aMultiArea
.aStart
.Col();
246 SCROW nStartRow
= aMultiArea
.aStart
.Row();
247 SCCOL nEndCol
= aMultiArea
.aEnd
.Col();
248 SCROW nEndRow
= aMultiArea
.aEnd
.Row();
250 bool bChanged
= false;
251 ScMarkData::iterator itr
= rMark
.begin(), itrEnd
= rMark
.end();
252 for (; itr
!= itrEnd
; ++itr
)
255 for (SCROW nRow
= nStartRow
; nRow
<= nEndRow
; ++nRow
)
257 SCROW nLastRow
= nRow
;
258 if (pDoc
->RowFiltered(nRow
, nTab
, NULL
, &nLastRow
))
260 // use nStartCol/nEndCol, so the multi mark area isn't extended to all columns
261 // (visible in repaint for indentation)
262 rMark
.SetMultiMarkArea(
263 ScRange(nStartCol
, nRow
, nTab
, nEndCol
, nLastRow
, nTab
), false);
270 if ( bChanged
&& !rMark
.HasAnyMultiMarks() )
273 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
);
342 sal_Bool
ScViewUtil::ExecuteCharMap( const SvxFontItem
& rOldFont
,
343 SfxViewFrame
& rFrame
,
344 SvxFontItem
& rNewFont
,
347 sal_Bool bRet
= false;
348 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
351 SfxAllItemSet
aSet( rFrame
.GetObjectShell()->GetPool() );
352 aSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
353 aSet
.Put( SvxFontItem( rOldFont
.GetFamily(), rOldFont
.GetFamilyName(), rOldFont
.GetStyleName(), rOldFont
.GetPitch(), rOldFont
.GetCharSet(), aSet
.GetPool()->GetWhich( SID_ATTR_CHAR_FONT
) ) );
354 SfxAbstractDialog
* pDlg
= pFact
->CreateSfxDialog( &rFrame
.GetWindow(), aSet
, rFrame
.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP
);
355 if ( pDlg
->Execute() == RET_OK
)
357 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pItem
, SfxStringItem
, SID_CHARMAP
, false );
358 SFX_ITEMSET_ARG( pDlg
->GetOutputItemSet(), pFontItem
, SvxFontItem
, SID_ATTR_CHAR_FONT
, false );
360 rString
= pItem
->GetValue();
362 rNewFont
= SvxFontItem( pFontItem
->GetFamily(), pFontItem
->GetFamilyName(), pFontItem
->GetStyleName(), pFontItem
->GetPitch(), pFontItem
->GetCharSet(), rNewFont
.Which() );
370 bool ScViewUtil::IsFullScreen( SfxViewShell
& rViewShell
)
372 SfxBindings
& rBindings
= rViewShell
.GetViewFrame()->GetBindings();
373 SfxPoolItem
* pItem
= 0;
374 bool bIsFullScreen
= false;
376 if (rBindings
.QueryState( SID_WIN_FULLSCREEN
, pItem
) >= SFX_ITEM_DEFAULT
)
377 bIsFullScreen
= static_cast< SfxBoolItem
* >( pItem
)->GetValue();
380 return bIsFullScreen
;
383 void ScViewUtil::SetFullScreen( SfxViewShell
& rViewShell
, bool bSet
)
385 if( IsFullScreen( rViewShell
) != bSet
)
387 SfxBoolItem
aItem( SID_WIN_FULLSCREEN
, bSet
);
388 rViewShell
.GetDispatcher()->Execute( SID_WIN_FULLSCREEN
, SFX_CALLMODE_RECORD
, &aItem
, 0L );
393 ScUpdateRect::ScUpdateRect( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
)
395 PutInOrder( nX1
, nX2
);
396 PutInOrder( nY1
, nY2
);
404 void ScUpdateRect::SetNew( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
)
406 PutInOrder( nX1
, nX2
);
407 PutInOrder( nY1
, nY2
);
415 sal_Bool
ScUpdateRect::GetDiff( SCCOL
& rX1
, SCROW
& rY1
, SCCOL
& rX2
, SCROW
& rY2
)
417 if ( nNewStartX
== nOldStartX
&& nNewEndX
== nOldEndX
&&
418 nNewStartY
== nOldStartY
&& nNewEndY
== nOldEndY
)
427 rX1
= std::min(nNewStartX
,nOldStartX
);
428 rY1
= std::min(nNewStartY
,nOldStartY
);
429 rX2
= std::max(nNewEndX
,nOldEndX
);
430 rY2
= std::max(nNewEndY
,nOldEndY
);
432 if ( nNewStartX
== nOldStartX
&& nNewEndX
== nOldEndX
)
434 if ( nNewStartY
== nOldStartY
)
436 rY1
= std::min( nNewEndY
, nOldEndY
);
437 rY2
= std::max( nNewEndY
, nOldEndY
);
439 else if ( nNewEndY
== nOldEndY
)
441 rY1
= std::min( nNewStartY
, nOldStartY
);
442 rY2
= std::max( nNewStartY
, nOldStartY
);
445 else if ( nNewStartY
== nOldStartY
&& nNewEndY
== nOldEndY
)
447 if ( nNewStartX
== nOldStartX
)
449 rX1
= std::min( nNewEndX
, nOldEndX
);
450 rX2
= std::max( nNewEndX
, nOldEndX
);
452 else if ( nNewEndX
== nOldEndX
)
454 rX1
= std::min( nNewStartX
, nOldStartX
);
455 rX2
= std::max( nNewStartX
, nOldStartX
);
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */