Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 :
19 : #include "scitems.hxx"
20 : #include <sfx2/bindings.hxx>
21 : #include <sfx2/viewsh.hxx>
22 : #include <sfx2/dispatch.hxx>
23 : #include <editeng/fontitem.hxx>
24 : #include <editeng/langitem.hxx>
25 : #include <editeng/scripttypeitem.hxx>
26 : #include <svl/itempool.hxx>
27 : #include <svl/itemset.hxx>
28 : #include <svl/cjkoptions.hxx>
29 : #include <svl/ctloptions.hxx>
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/msgbox.hxx>
32 : #include <vcl/wrkwin.hxx>
33 : #include <vcl/settings.hxx>
34 : #include <sfx2/request.hxx>
35 : #include <sfx2/objsh.hxx>
36 : #include <svl/stritem.hxx>
37 : #include <svl/eitem.hxx>
38 :
39 : #include <com/sun/star/i18n/TransliterationModules.hpp>
40 : #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
41 :
42 : #include "viewutil.hxx"
43 : #include "global.hxx"
44 : #include "chgtrack.hxx"
45 : #include "chgviset.hxx"
46 : #include "markdata.hxx"
47 : #include "document.hxx"
48 :
49 : #include <svx/svxdlg.hxx>
50 : #include <svx/dialogs.hrc>
51 :
52 :
53 0 : void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSet,
54 : sal_uInt16 nWhichId, sal_uInt16 nScript )
55 : {
56 : // take the effective item from rCoreSet according to nScript
57 : // and put in rShellSet under the (base) nWhichId
58 :
59 0 : SfxItemPool& rPool = *rShellSet.GetPool();
60 0 : 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 0 : aSetItem.GetItemSet().PutExtended( rCoreSet, SFX_ITEM_DONTCARE, SFX_ITEM_SET );
64 0 : const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
65 0 : if (pI)
66 0 : rShellSet.Put( *pI, nWhichId );
67 : else
68 0 : rShellSet.InvalidateItem( nWhichId );
69 0 : }
70 :
71 0 : sal_uInt16 ScViewUtil::GetEffLanguage( ScDocument* pDoc, const ScAddress& rPos )
72 : {
73 : // used for thesaurus
74 :
75 0 : sal_uInt8 nScript = pDoc->GetScriptType(rPos.Col(), rPos.Row(), rPos.Tab());
76 : sal_uInt16 nWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? ATTR_CJK_FONT_LANGUAGE :
77 0 : ( ( nScript == SCRIPTTYPE_COMPLEX ) ? ATTR_CTL_FONT_LANGUAGE : ATTR_FONT_LANGUAGE );
78 0 : const SfxPoolItem* pItem = pDoc->GetAttr( rPos.Col(), rPos.Row(), rPos.Tab(), nWhich);
79 0 : SvxLanguageItem* pLangIt = PTR_CAST( SvxLanguageItem, pItem );
80 : LanguageType eLnge;
81 0 : if (pLangIt)
82 : {
83 0 : eLnge = (LanguageType) pLangIt->GetValue();
84 0 : if (eLnge == LANGUAGE_DONTKNOW) //! can this happen?
85 : {
86 : LanguageType eLatin, eCjk, eCtl;
87 0 : pDoc->GetLanguage( eLatin, eCjk, eCtl );
88 : eLnge = ( nScript == SCRIPTTYPE_ASIAN ) ? eCjk :
89 0 : ( ( nScript == SCRIPTTYPE_COMPLEX ) ? eCtl : eLatin );
90 : }
91 : }
92 : else
93 0 : eLnge = LANGUAGE_ENGLISH_US;
94 0 : if ( eLnge == LANGUAGE_SYSTEM )
95 0 : eLnge = Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
96 :
97 0 : return eLnge;
98 : }
99 :
100 0 : sal_Int32 ScViewUtil::GetTransliterationType( sal_uInt16 nSlotID )
101 : {
102 0 : sal_Int32 nType = 0;
103 0 : switch ( nSlotID )
104 : {
105 : case SID_TRANSLITERATE_SENTENCE_CASE:
106 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE;
107 0 : break;
108 : case SID_TRANSLITERATE_TITLE_CASE:
109 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE;
110 0 : break;
111 : case SID_TRANSLITERATE_TOGGLE_CASE:
112 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::TOGGLE_CASE;
113 0 : break;
114 : case SID_TRANSLITERATE_UPPER:
115 0 : nType = com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE;
116 0 : break;
117 : case SID_TRANSLITERATE_LOWER:
118 0 : nType = com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE;
119 0 : break;
120 : case SID_TRANSLITERATE_HALFWIDTH:
121 0 : nType = com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH;
122 0 : break;
123 : case SID_TRANSLITERATE_FULLWIDTH:
124 0 : nType = com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH;
125 0 : break;
126 : case SID_TRANSLITERATE_HIRAGANA:
127 0 : nType = com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA;
128 0 : break;
129 : case SID_TRANSLITERATE_KATAGANA:
130 0 : nType = com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA;
131 0 : break;
132 : }
133 0 : return nType;
134 : }
135 :
136 0 : bool ScViewUtil::IsActionShown( const ScChangeAction& rAction,
137 : const ScChangeViewSettings& rSettings,
138 : ScDocument& rDocument )
139 : {
140 : // discarded are displayed as inverted accepted action, because of this
141 : // order of ShowRejected/ShowAccepted is important
142 :
143 0 : if ( !rSettings.IsShowRejected() && rAction.IsRejecting() )
144 0 : return false;
145 :
146 0 : if ( !rSettings.IsShowAccepted() && rAction.IsAccepted() && !rAction.IsRejecting() )
147 0 : return false;
148 :
149 0 : if ( rSettings.HasAuthor() )
150 : {
151 0 : if ( rSettings.IsEveryoneButMe() )
152 : {
153 : // GetUser() at ChangeTrack is the current user
154 0 : ScChangeTrack* pTrack = rDocument.GetChangeTrack();
155 0 : if ( !pTrack || rAction.GetUser().equals(pTrack->GetUser()) )
156 0 : return false;
157 : }
158 0 : else if ( !rAction.GetUser().equals(rSettings.GetTheAuthorToShow()) )
159 0 : return false;
160 : }
161 :
162 0 : if ( rSettings.HasComment() )
163 : {
164 0 : OUStringBuffer aBuf(rAction.GetComment());
165 0 : aBuf.append(" (");
166 0 : OUString aTmp;
167 0 : rAction.GetDescription(aTmp, &rDocument);
168 0 : aBuf.append(aTmp);
169 0 : aBuf.append(')');
170 0 : OUString aComStr = aBuf.makeStringAndClear();
171 :
172 0 : if(!rSettings.IsValidComment(&aComStr))
173 0 : return false;
174 : }
175 :
176 0 : if ( rSettings.HasRange() )
177 0 : if ( !rSettings.GetTheRangeList().Intersects( rAction.GetBigRange().MakeRange() ) )
178 0 : return false;
179 :
180 0 : if ( rSettings.HasDate() && rSettings.GetTheDateMode() != SCDM_NO_DATEMODE )
181 : {
182 0 : DateTime aDateTime = rAction.GetDateTime();
183 0 : const DateTime& rFirst = rSettings.GetTheFirstDateTime();
184 0 : const DateTime& rLast = rSettings.GetTheLastDateTime();
185 0 : switch ( rSettings.GetTheDateMode() )
186 : { // corresponds with ScHighlightChgDlg::OKBtnHdl
187 : case SCDM_DATE_BEFORE:
188 0 : if ( aDateTime > rFirst )
189 0 : return false;
190 0 : break;
191 :
192 : case SCDM_DATE_SINCE:
193 0 : if ( aDateTime < rFirst )
194 0 : return false;
195 0 : break;
196 :
197 : case SCDM_DATE_EQUAL:
198 : case SCDM_DATE_BETWEEN:
199 0 : if ( aDateTime < rFirst || aDateTime > rLast )
200 0 : return false;
201 0 : break;
202 :
203 : case SCDM_DATE_NOTEQUAL:
204 0 : if ( aDateTime >= rFirst && aDateTime <= rLast )
205 0 : return false;
206 0 : break;
207 :
208 : case SCDM_DATE_SAVE:
209 : {
210 0 : ScChangeTrack* pTrack = rDocument.GetChangeTrack();
211 0 : if ( !pTrack || pTrack->GetLastSavedActionNumber() >=
212 0 : rAction.GetActionNumber() )
213 0 : return false;
214 : }
215 0 : break;
216 :
217 : default:
218 : {
219 : // added to avoid warnings
220 : }
221 : }
222 : }
223 :
224 0 : if ( rSettings.HasActionRange() )
225 : {
226 0 : sal_uLong nAction = rAction.GetActionNumber();
227 : sal_uLong nFirstAction;
228 : sal_uLong nLastAction;
229 0 : rSettings.GetTheActionRange( nFirstAction, nLastAction );
230 0 : if ( nAction < nFirstAction || nAction > nLastAction )
231 : {
232 0 : return false;
233 : }
234 : }
235 :
236 0 : return true;
237 : }
238 :
239 0 : void ScViewUtil::UnmarkFiltered( ScMarkData& rMark, ScDocument* pDoc )
240 : {
241 0 : rMark.MarkToMulti();
242 :
243 0 : ScRange aMultiArea;
244 0 : rMark.GetMultiMarkArea( aMultiArea );
245 0 : SCCOL nStartCol = aMultiArea.aStart.Col();
246 0 : SCROW nStartRow = aMultiArea.aStart.Row();
247 0 : SCCOL nEndCol = aMultiArea.aEnd.Col();
248 0 : SCROW nEndRow = aMultiArea.aEnd.Row();
249 :
250 0 : bool bChanged = false;
251 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
252 0 : for (; itr != itrEnd; ++itr)
253 : {
254 0 : SCTAB nTab = *itr;
255 0 : for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
256 : {
257 0 : SCROW nLastRow = nRow;
258 0 : if (pDoc->RowFiltered(nRow, nTab, NULL, &nLastRow))
259 : {
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 0 : ScRange(nStartCol, nRow, nTab, nEndCol, nLastRow, nTab), false);
264 0 : bChanged = true;
265 0 : nRow = nLastRow;
266 : }
267 : }
268 : }
269 :
270 0 : if ( bChanged && !rMark.HasAnyMultiMarks() )
271 0 : rMark.ResetMark();
272 :
273 0 : rMark.MarkToSimple();
274 0 : }
275 :
276 :
277 0 : bool ScViewUtil::FitToUnfilteredRows( ScRange & rRange, ScDocument * pDoc, size_t nRows )
278 : {
279 0 : SCTAB nTab = rRange.aStart.Tab();
280 0 : 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 0 : SCROW nStartRow = rRange.aStart.Row();
284 0 : SCROW nLastRow = pDoc->LastNonFilteredRow(nStartRow, MAXROW, nTab);
285 0 : if (ValidRow(nLastRow))
286 0 : rRange.aEnd.SetRow(nLastRow);
287 0 : SCROW nCount = pDoc->CountNonFilteredRows(nStartRow, MAXROW, nTab);
288 0 : return static_cast<size_t>(nCount) == nRows && bOneTabOnly;
289 : }
290 :
291 0 : bool ScViewUtil::HasFiltered( const ScRange& rRange, ScDocument* pDoc )
292 : {
293 0 : SCROW nStartRow = rRange.aStart.Row();
294 0 : SCROW nEndRow = rRange.aEnd.Row();
295 0 : for (SCTAB nTab=rRange.aStart.Tab(); nTab<=rRange.aEnd.Tab(); nTab++)
296 : {
297 0 : if (pDoc->HasFilteredRows(nStartRow, nEndRow, nTab))
298 0 : return true;
299 : }
300 :
301 0 : return false;
302 : }
303 :
304 0 : void ScViewUtil::HideDisabledSlot( SfxItemSet& rSet, SfxBindings& rBindings, sal_uInt16 nSlotId )
305 : {
306 0 : SvtCJKOptions aCJKOptions;
307 0 : SvtCTLOptions aCTLOptions;
308 0 : bool bEnabled = true;
309 :
310 0 : switch( nSlotId )
311 : {
312 : case SID_CHINESE_CONVERSION:
313 : case SID_HANGUL_HANJA_CONVERSION:
314 0 : bEnabled = aCJKOptions.IsAnyEnabled();
315 0 : break;
316 :
317 : case SID_TRANSLITERATE_HALFWIDTH:
318 : case SID_TRANSLITERATE_FULLWIDTH:
319 : case SID_TRANSLITERATE_HIRAGANA:
320 : case SID_TRANSLITERATE_KATAGANA:
321 0 : bEnabled = aCJKOptions.IsChangeCaseMapEnabled();
322 0 : break;
323 :
324 : case SID_INSERT_RLM:
325 : case SID_INSERT_LRM:
326 : case SID_INSERT_ZWNBSP:
327 : case SID_INSERT_ZWSP:
328 0 : bEnabled = aCTLOptions.IsCTLFontEnabled();
329 0 : break;
330 :
331 : default:
332 : OSL_FAIL( "ScViewUtil::HideDisabledSlot - unknown slot ID" );
333 0 : return;
334 : }
335 :
336 0 : rBindings.SetVisibleState( nSlotId, bEnabled );
337 0 : if( !bEnabled )
338 0 : rSet.DisableItem( nSlotId );
339 : }
340 :
341 :
342 0 : bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
343 : SfxViewFrame& rFrame,
344 : SvxFontItem& rNewFont,
345 : OUString& rString )
346 : {
347 0 : bool bRet = false;
348 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
349 0 : if(pFact)
350 : {
351 0 : SfxAllItemSet aSet( rFrame.GetObjectShell()->GetPool() );
352 0 : aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
353 0 : aSet.Put( SvxFontItem( rOldFont.GetFamily(), rOldFont.GetFamilyName(), rOldFont.GetStyleName(), rOldFont.GetPitch(), rOldFont.GetCharSet(), aSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT ) ) );
354 0 : SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( &rFrame.GetWindow(), aSet, rFrame.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
355 0 : if ( pDlg->Execute() == RET_OK )
356 : {
357 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
358 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
359 0 : if ( pItem )
360 0 : rString = pItem->GetValue();
361 0 : if ( pFontItem )
362 0 : rNewFont = SvxFontItem( pFontItem->GetFamily(), pFontItem->GetFamilyName(), pFontItem->GetStyleName(), pFontItem->GetPitch(), pFontItem->GetCharSet(), rNewFont.Which() );
363 0 : bRet = true;
364 : }
365 0 : delete pDlg;
366 : }
367 0 : return bRet;
368 : }
369 :
370 0 : bool ScViewUtil::IsFullScreen( SfxViewShell& rViewShell )
371 : {
372 0 : SfxBindings& rBindings = rViewShell.GetViewFrame()->GetBindings();
373 0 : SfxPoolItem* pItem = 0;
374 0 : bool bIsFullScreen = false;
375 :
376 0 : if (rBindings.QueryState( SID_WIN_FULLSCREEN, pItem ) >= SFX_ITEM_DEFAULT)
377 0 : bIsFullScreen = static_cast< SfxBoolItem* >( pItem )->GetValue();
378 0 : delete pItem;
379 :
380 0 : return bIsFullScreen;
381 : }
382 :
383 0 : void ScViewUtil::SetFullScreen( SfxViewShell& rViewShell, bool bSet )
384 : {
385 0 : if( IsFullScreen( rViewShell ) != bSet )
386 : {
387 0 : SfxBoolItem aItem( SID_WIN_FULLSCREEN, bSet );
388 0 : rViewShell.GetDispatcher()->Execute( SID_WIN_FULLSCREEN, SFX_CALLMODE_RECORD, &aItem, 0L );
389 : }
390 0 : }
391 :
392 :
393 0 : ScUpdateRect::ScUpdateRect( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
394 : : nNewStartX(0)
395 : , nNewStartY(0)
396 : , nNewEndX(0)
397 0 : , nNewEndY(0)
398 : {
399 0 : PutInOrder( nX1, nX2 );
400 0 : PutInOrder( nY1, nY2 );
401 :
402 0 : nOldStartX = nX1;
403 0 : nOldStartY = nY1;
404 0 : nOldEndX = nX2;
405 0 : nOldEndY = nY2;
406 0 : }
407 :
408 0 : void ScUpdateRect::SetNew( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
409 : {
410 0 : PutInOrder( nX1, nX2 );
411 0 : PutInOrder( nY1, nY2 );
412 :
413 0 : nNewStartX = nX1;
414 0 : nNewStartY = nY1;
415 0 : nNewEndX = nX2;
416 0 : nNewEndY = nY2;
417 0 : }
418 :
419 0 : bool ScUpdateRect::GetDiff( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
420 : {
421 0 : if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX &&
422 0 : nNewStartY == nOldStartY && nNewEndY == nOldEndY )
423 : {
424 0 : rX1 = nNewStartX;
425 0 : rY1 = nNewStartY;
426 0 : rX2 = nNewStartX;
427 0 : rY2 = nNewStartY;
428 0 : return false;
429 : }
430 :
431 0 : rX1 = std::min(nNewStartX,nOldStartX);
432 0 : rY1 = std::min(nNewStartY,nOldStartY);
433 0 : rX2 = std::max(nNewEndX,nOldEndX);
434 0 : rY2 = std::max(nNewEndY,nOldEndY);
435 :
436 0 : if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX )
437 : {
438 0 : if ( nNewStartY == nOldStartY )
439 : {
440 0 : rY1 = std::min( nNewEndY, nOldEndY );
441 0 : rY2 = std::max( nNewEndY, nOldEndY );
442 : }
443 0 : else if ( nNewEndY == nOldEndY )
444 : {
445 0 : rY1 = std::min( nNewStartY, nOldStartY );
446 0 : rY2 = std::max( nNewStartY, nOldStartY );
447 : }
448 : }
449 0 : else if ( nNewStartY == nOldStartY && nNewEndY == nOldEndY )
450 : {
451 0 : if ( nNewStartX == nOldStartX )
452 : {
453 0 : rX1 = std::min( nNewEndX, nOldEndX );
454 0 : rX2 = std::max( nNewEndX, nOldEndX );
455 : }
456 0 : else if ( nNewEndX == nOldEndX )
457 : {
458 0 : rX1 = std::min( nNewStartX, nOldStartX );
459 0 : rX2 = std::max( nNewStartX, nOldStartX );
460 : }
461 : }
462 :
463 0 : return true;
464 0 : }
465 :
466 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|