Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
39 :
40 : #include <com/sun/star/i18n/TransliterationModules.hpp>
41 : #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
42 :
43 : #include "viewutil.hxx"
44 : #include "global.hxx"
45 : #include "chgtrack.hxx"
46 : #include "chgviset.hxx"
47 : #include "markdata.hxx"
48 : #include "document.hxx"
49 :
50 : #include <svx/svxdlg.hxx>
51 : #include <svx/dialogs.hrc>
52 : #include <boost/scoped_ptr.hpp>
53 :
54 1220 : void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSet,
55 : sal_uInt16 nWhichId, sal_uInt16 nScript )
56 : {
57 : // take the effective item from rCoreSet according to nScript
58 : // and put in rShellSet under the (base) nWhichId
59 :
60 1220 : SfxItemPool& rPool = *rShellSet.GetPool();
61 1220 : 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 1220 : aSetItem.GetItemSet().PutExtended( rCoreSet, SfxItemState::DONTCARE, SfxItemState::SET );
65 1220 : const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
66 1220 : if (pI)
67 1220 : rShellSet.Put( *pI, nWhichId );
68 : else
69 0 : rShellSet.InvalidateItem( nWhichId );
70 1220 : }
71 :
72 0 : sal_uInt16 ScViewUtil::GetEffLanguage( ScDocument* pDoc, const ScAddress& rPos )
73 : {
74 : // used for thesaurus
75 :
76 0 : sal_uInt8 nScript = pDoc->GetScriptType(rPos.Col(), rPos.Row(), rPos.Tab());
77 : sal_uInt16 nWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? ATTR_CJK_FONT_LANGUAGE :
78 0 : ( ( nScript == SCRIPTTYPE_COMPLEX ) ? ATTR_CTL_FONT_LANGUAGE : ATTR_FONT_LANGUAGE );
79 0 : const SfxPoolItem* pItem = pDoc->GetAttr( rPos.Col(), rPos.Row(), rPos.Tab(), nWhich);
80 0 : const SvxLanguageItem* pLangIt = PTR_CAST( SvxLanguageItem, pItem );
81 : LanguageType eLnge;
82 0 : if (pLangIt)
83 : {
84 0 : eLnge = (LanguageType) pLangIt->GetValue();
85 0 : if (eLnge == LANGUAGE_DONTKNOW) //! can this happen?
86 : {
87 : LanguageType eLatin, eCjk, eCtl;
88 0 : pDoc->GetLanguage( eLatin, eCjk, eCtl );
89 : eLnge = ( nScript == SCRIPTTYPE_ASIAN ) ? eCjk :
90 0 : ( ( nScript == SCRIPTTYPE_COMPLEX ) ? eCtl : eLatin );
91 : }
92 : }
93 : else
94 0 : eLnge = LANGUAGE_ENGLISH_US;
95 0 : if ( eLnge == LANGUAGE_SYSTEM )
96 0 : eLnge = Application::GetSettings().GetLanguageTag().getLanguageType(); // never use SYSTEM for spelling
97 :
98 0 : return eLnge;
99 : }
100 :
101 0 : sal_Int32 ScViewUtil::GetTransliterationType( sal_uInt16 nSlotID )
102 : {
103 0 : sal_Int32 nType = 0;
104 0 : switch ( nSlotID )
105 : {
106 : case SID_TRANSLITERATE_SENTENCE_CASE:
107 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::SENTENCE_CASE;
108 0 : break;
109 : case SID_TRANSLITERATE_TITLE_CASE:
110 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::TITLE_CASE;
111 0 : break;
112 : case SID_TRANSLITERATE_TOGGLE_CASE:
113 0 : nType = com::sun::star::i18n::TransliterationModulesExtra::TOGGLE_CASE;
114 0 : break;
115 : case SID_TRANSLITERATE_UPPER:
116 0 : nType = com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE;
117 0 : break;
118 : case SID_TRANSLITERATE_LOWER:
119 0 : nType = com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE;
120 0 : break;
121 : case SID_TRANSLITERATE_HALFWIDTH:
122 0 : nType = com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH;
123 0 : break;
124 : case SID_TRANSLITERATE_FULLWIDTH:
125 0 : nType = com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH;
126 0 : break;
127 : case SID_TRANSLITERATE_HIRAGANA:
128 0 : nType = com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA;
129 0 : break;
130 : case SID_TRANSLITERATE_KATAGANA:
131 0 : nType = com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA;
132 0 : break;
133 : }
134 0 : return nType;
135 : }
136 :
137 0 : bool ScViewUtil::IsActionShown( const ScChangeAction& rAction,
138 : const ScChangeViewSettings& rSettings,
139 : ScDocument& rDocument )
140 : {
141 : // discarded are displayed as inverted accepted action, because of this
142 : // order of ShowRejected/ShowAccepted is important
143 :
144 0 : if ( !rSettings.IsShowRejected() && rAction.IsRejecting() )
145 0 : return false;
146 :
147 0 : if ( !rSettings.IsShowAccepted() && rAction.IsAccepted() && !rAction.IsRejecting() )
148 0 : return false;
149 :
150 0 : if ( rSettings.HasAuthor() )
151 : {
152 0 : if ( rSettings.IsEveryoneButMe() )
153 : {
154 : // GetUser() at ChangeTrack is the current user
155 0 : ScChangeTrack* pTrack = rDocument.GetChangeTrack();
156 0 : if ( !pTrack || rAction.GetUser().equals(pTrack->GetUser()) )
157 0 : return false;
158 : }
159 0 : else if ( !rAction.GetUser().equals(rSettings.GetTheAuthorToShow()) )
160 0 : return false;
161 : }
162 :
163 0 : if ( rSettings.HasComment() )
164 : {
165 0 : OUStringBuffer aBuf(rAction.GetComment());
166 0 : aBuf.append(" (");
167 0 : OUString aTmp;
168 0 : rAction.GetDescription(aTmp, &rDocument);
169 0 : aBuf.append(aTmp);
170 0 : aBuf.append(')');
171 0 : OUString aComStr = aBuf.makeStringAndClear();
172 :
173 0 : if(!rSettings.IsValidComment(&aComStr))
174 0 : return false;
175 : }
176 :
177 0 : if ( rSettings.HasRange() )
178 0 : if ( !rSettings.GetTheRangeList().Intersects( rAction.GetBigRange().MakeRange() ) )
179 0 : return false;
180 :
181 0 : if ( rSettings.HasDate() && rSettings.GetTheDateMode() != SCDM_NO_DATEMODE )
182 : {
183 0 : DateTime aDateTime = rAction.GetDateTime();
184 0 : const DateTime& rFirst = rSettings.GetTheFirstDateTime();
185 0 : const DateTime& rLast = rSettings.GetTheLastDateTime();
186 0 : switch ( rSettings.GetTheDateMode() )
187 : { // corresponds with ScHighlightChgDlg::OKBtnHdl
188 : case SCDM_DATE_BEFORE:
189 0 : if ( aDateTime > rFirst )
190 0 : return false;
191 0 : break;
192 :
193 : case SCDM_DATE_SINCE:
194 0 : if ( aDateTime < rFirst )
195 0 : return false;
196 0 : break;
197 :
198 : case SCDM_DATE_EQUAL:
199 : case SCDM_DATE_BETWEEN:
200 0 : if ( aDateTime < rFirst || aDateTime > rLast )
201 0 : return false;
202 0 : break;
203 :
204 : case SCDM_DATE_NOTEQUAL:
205 0 : if ( aDateTime >= rFirst && aDateTime <= rLast )
206 0 : return false;
207 0 : break;
208 :
209 : case SCDM_DATE_SAVE:
210 : {
211 0 : ScChangeTrack* pTrack = rDocument.GetChangeTrack();
212 0 : if ( !pTrack || pTrack->GetLastSavedActionNumber() >=
213 0 : rAction.GetActionNumber() )
214 0 : return false;
215 : }
216 0 : break;
217 :
218 : default:
219 : {
220 : // added to avoid warnings
221 : }
222 : }
223 : }
224 :
225 0 : if ( rSettings.HasActionRange() )
226 : {
227 0 : sal_uLong nAction = rAction.GetActionNumber();
228 : sal_uLong nFirstAction;
229 : sal_uLong nLastAction;
230 0 : rSettings.GetTheActionRange( nFirstAction, nLastAction );
231 0 : if ( nAction < nFirstAction || nAction > nLastAction )
232 : {
233 0 : return false;
234 : }
235 : }
236 :
237 0 : return true;
238 : }
239 :
240 232 : void ScViewUtil::UnmarkFiltered( ScMarkData& rMark, ScDocument* pDoc )
241 : {
242 232 : rMark.MarkToMulti();
243 :
244 232 : ScRange aMultiArea;
245 232 : rMark.GetMultiMarkArea( aMultiArea );
246 232 : SCCOL nStartCol = aMultiArea.aStart.Col();
247 232 : SCROW nStartRow = aMultiArea.aStart.Row();
248 232 : SCCOL nEndCol = aMultiArea.aEnd.Col();
249 232 : SCROW nEndRow = aMultiArea.aEnd.Row();
250 :
251 232 : bool bChanged = false;
252 232 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
253 464 : for (; itr != itrEnd; ++itr)
254 : {
255 232 : SCTAB nTab = *itr;
256 474 : for (SCROW nRow = nStartRow; nRow <= nEndRow; ++nRow)
257 : {
258 242 : SCROW nLastRow = nRow;
259 242 : if (pDoc->RowFiltered(nRow, nTab, NULL, &nLastRow))
260 : {
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 0 : ScRange(nStartCol, nRow, nTab, nEndCol, nLastRow, nTab), false);
265 0 : bChanged = true;
266 0 : nRow = nLastRow;
267 : }
268 : }
269 : }
270 :
271 232 : if ( bChanged && !rMark.HasAnyMultiMarks() )
272 0 : rMark.ResetMark();
273 :
274 232 : rMark.MarkToSimple();
275 232 : }
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 1757 : bool ScViewUtil::HasFiltered( const ScRange& rRange, ScDocument* pDoc )
292 : {
293 1757 : SCROW nStartRow = rRange.aStart.Row();
294 1757 : SCROW nEndRow = rRange.aEnd.Row();
295 3514 : for (SCTAB nTab=rRange.aStart.Tab(); nTab<=rRange.aEnd.Tab(); nTab++)
296 : {
297 1757 : if (pDoc->HasFilteredRows(nStartRow, nEndRow, nTab))
298 0 : return true;
299 : }
300 :
301 1757 : 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 0 : bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
342 : SfxViewFrame& rFrame,
343 : SvxFontItem& rNewFont,
344 : OUString& rString )
345 : {
346 0 : bool bRet = false;
347 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
348 0 : if(pFact)
349 : {
350 0 : SfxAllItemSet aSet( rFrame.GetObjectShell()->GetPool() );
351 0 : aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
352 0 : aSet.Put( SvxFontItem( rOldFont.GetFamily(), rOldFont.GetFamilyName(), rOldFont.GetStyleName(), rOldFont.GetPitch(), rOldFont.GetCharSet(), aSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT ) ) );
353 0 : boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( &rFrame.GetWindow(), aSet, rFrame.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
354 0 : if ( pDlg->Execute() == RET_OK )
355 : {
356 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
357 0 : SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
358 0 : if ( pItem )
359 0 : rString = pItem->GetValue();
360 0 : if ( pFontItem )
361 0 : rNewFont = SvxFontItem( pFontItem->GetFamily(), pFontItem->GetFamilyName(), pFontItem->GetStyleName(), pFontItem->GetPitch(), pFontItem->GetCharSet(), rNewFont.Which() );
362 0 : bRet = true;
363 0 : }
364 : }
365 0 : return bRet;
366 : }
367 :
368 0 : bool ScViewUtil::IsFullScreen( SfxViewShell& rViewShell )
369 : {
370 0 : SfxBindings& rBindings = rViewShell.GetViewFrame()->GetBindings();
371 0 : SfxPoolItem* pItem = 0;
372 0 : bool bIsFullScreen = false;
373 :
374 0 : if (rBindings.QueryState( SID_WIN_FULLSCREEN, pItem ) >= SfxItemState::DEFAULT)
375 0 : bIsFullScreen = static_cast< SfxBoolItem* >( pItem )->GetValue();
376 0 : delete pItem;
377 :
378 0 : return bIsFullScreen;
379 : }
380 :
381 0 : void ScViewUtil::SetFullScreen( SfxViewShell& rViewShell, bool bSet )
382 : {
383 0 : if( IsFullScreen( rViewShell ) != bSet )
384 : {
385 0 : SfxBoolItem aItem( SID_WIN_FULLSCREEN, bSet );
386 0 : rViewShell.GetDispatcher()->Execute( SID_WIN_FULLSCREEN, SfxCallMode::RECORD, &aItem, 0L );
387 : }
388 0 : }
389 :
390 0 : ScUpdateRect::ScUpdateRect( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
391 : : nNewStartX(0)
392 : , nNewStartY(0)
393 : , nNewEndX(0)
394 0 : , nNewEndY(0)
395 : {
396 0 : PutInOrder( nX1, nX2 );
397 0 : PutInOrder( nY1, nY2 );
398 :
399 0 : nOldStartX = nX1;
400 0 : nOldStartY = nY1;
401 0 : nOldEndX = nX2;
402 0 : nOldEndY = nY2;
403 0 : }
404 :
405 0 : void ScUpdateRect::SetNew( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 )
406 : {
407 0 : PutInOrder( nX1, nX2 );
408 0 : PutInOrder( nY1, nY2 );
409 :
410 0 : nNewStartX = nX1;
411 0 : nNewStartY = nY1;
412 0 : nNewEndX = nX2;
413 0 : nNewEndY = nY2;
414 0 : }
415 :
416 0 : bool ScUpdateRect::GetDiff( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 )
417 : {
418 0 : if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX &&
419 0 : nNewStartY == nOldStartY && nNewEndY == nOldEndY )
420 : {
421 0 : rX1 = nNewStartX;
422 0 : rY1 = nNewStartY;
423 0 : rX2 = nNewStartX;
424 0 : rY2 = nNewStartY;
425 0 : return false;
426 : }
427 :
428 0 : rX1 = std::min(nNewStartX,nOldStartX);
429 0 : rY1 = std::min(nNewStartY,nOldStartY);
430 0 : rX2 = std::max(nNewEndX,nOldEndX);
431 0 : rY2 = std::max(nNewEndY,nOldEndY);
432 :
433 0 : if ( nNewStartX == nOldStartX && nNewEndX == nOldEndX )
434 : {
435 0 : if ( nNewStartY == nOldStartY )
436 : {
437 0 : rY1 = std::min( nNewEndY, nOldEndY );
438 0 : rY2 = std::max( nNewEndY, nOldEndY );
439 : }
440 0 : else if ( nNewEndY == nOldEndY )
441 : {
442 0 : rY1 = std::min( nNewStartY, nOldStartY );
443 0 : rY2 = std::max( nNewStartY, nOldStartY );
444 : }
445 : }
446 0 : else if ( nNewStartY == nOldStartY && nNewEndY == nOldEndY )
447 : {
448 0 : if ( nNewStartX == nOldStartX )
449 : {
450 0 : rX1 = std::min( nNewEndX, nOldEndX );
451 0 : rX2 = std::max( nNewEndX, nOldEndX );
452 : }
453 0 : else if ( nNewEndX == nOldEndX )
454 : {
455 0 : rX1 = std::min( nNewStartX, nOldStartX );
456 0 : rX2 = std::max( nNewStartX, nOldStartX );
457 : }
458 : }
459 :
460 0 : return true;
461 228 : }
462 :
463 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|