/src/libreoffice/sc/source/ui/docshell/docsh4.cxx
Line | Count | Source |
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 <config_features.h> |
21 | | |
22 | | #include <com/sun/star/frame/Desktop.hpp> |
23 | | |
24 | | #include <scitems.hxx> |
25 | | #include <sfx2/viewfrm.hxx> |
26 | | #include <drawview.hxx> |
27 | | #include <editeng/flstitem.hxx> |
28 | | #include <sfx2/fcontnr.hxx> |
29 | | #include <sfx2/linkmgr.hxx> |
30 | | #include <sfx2/objface.hxx> |
31 | | #include <sfx2/docfile.hxx> |
32 | | #include <sfx2/docfilt.hxx> |
33 | | #include <svtools/ehdl.hxx> |
34 | | #include <svtools/langtab.hxx> |
35 | | #include <basic/sbxcore.hxx> |
36 | | #include <basic/sberrors.hxx> |
37 | | #include <svtools/sfxecode.hxx> |
38 | | #include <svx/ofaitem.hxx> |
39 | | #include <svx/svdograf.hxx> |
40 | | #include <svl/stritem.hxx> |
41 | | #include <svl/whiter.hxx> |
42 | | #include <vcl/svapp.hxx> |
43 | | #include <vcl/weld/MessageDialog.hxx> |
44 | | #include <vcl/weld/WaitObject.hxx> |
45 | | #include <svx/dataaccessdescriptor.hxx> |
46 | | #include <svx/drawitem.hxx> |
47 | | #include <svx/fmshell.hxx> |
48 | | #include <svx/pageitem.hxx> |
49 | | #include <editeng/sizeitem.hxx> |
50 | | #include <editeng/paperinf.hxx> |
51 | | #include <sfx2/passwd.hxx> |
52 | | #include <sfx2/filedlghelper.hxx> |
53 | | #include <sfx2/dispatch.hxx> |
54 | | #include <sfx2/sfxdlg.hxx> |
55 | | #include <svl/PasswordHelper.hxx> |
56 | | #include <svl/documentlockfile.hxx> |
57 | | #include <svl/sharecontrolfile.hxx> |
58 | | #include <tools/json_writer.hxx> |
59 | | #include <unotools/securityoptions.hxx> |
60 | | #include <LibreOfficeKit/LibreOfficeKitEnums.h> |
61 | | #include <sal/log.hxx> |
62 | | #include <unotools/charclass.hxx> |
63 | | #include <comphelper/diagnose_ex.hxx> |
64 | | #include <o3tl/string_view.hxx> |
65 | | |
66 | | #include <comphelper/lok.hxx> |
67 | | #include <comphelper/processfactory.hxx> |
68 | | #include <comphelper/propertyvalue.hxx> |
69 | | #include <docuno.hxx> |
70 | | |
71 | | #include <docsh.hxx> |
72 | | #include "docshimp.hxx" |
73 | | #include <docfunc.hxx> |
74 | | #include <scres.hrc> |
75 | | #include <strings.hrc> |
76 | | #include <stlsheet.hxx> |
77 | | #include <stlpool.hxx> |
78 | | #include <appoptio.hxx> |
79 | | #include <globstr.hrc> |
80 | | #include <global.hxx> |
81 | | #include <dbdocfun.hxx> |
82 | | #include <printfun.hxx> |
83 | | #include <viewdata.hxx> |
84 | | #include <tabvwsh.hxx> |
85 | | #include <impex.hxx> |
86 | | #include <undodat.hxx> |
87 | | #include <undocell.hxx> |
88 | | #include <inputhdl.hxx> |
89 | | #include <dbdata.hxx> |
90 | | #include <servobj.hxx> |
91 | | #include <rangenam.hxx> |
92 | | #include <scmod.hxx> |
93 | | #include <chgviset.hxx> |
94 | | #include <reffact.hxx> |
95 | | #include <chartlis.hxx> |
96 | | #include <chartpos.hxx> |
97 | | #include <tablink.hxx> |
98 | | #include <drwlayer.hxx> |
99 | | #include <svx/fillbitmaplink.hxx> |
100 | | #include <svx/svdpage.hxx> |
101 | | #include <docoptio.hxx> |
102 | | #include <undostyl.hxx> |
103 | | #include <rangeseq.hxx> |
104 | | #include <chgtrack.hxx> |
105 | | #include <com/sun/star/document/UpdateDocMode.hpp> |
106 | | #include <scresid.hxx> |
107 | | #include <scabstdlg.hxx> |
108 | | #include <sharedocdlg.hxx> |
109 | | #include <conditio.hxx> |
110 | | #include <sheetevents.hxx> |
111 | | #include <formulacell.hxx> |
112 | | #include <documentlinkmgr.hxx> |
113 | | #include <tablestyle.hxx> |
114 | | #include <memory> |
115 | | #include <sfx2/notebookbar/SfxNotebookBar.hxx> |
116 | | #include <helpids.h> |
117 | | #include <editeng/eeitem.hxx> |
118 | | #include <editeng/langitem.hxx> |
119 | | #include <editeng/urlfieldhelper.hxx> |
120 | | #include <officecfg/Office/Common.hxx> |
121 | | |
122 | | #include <svx/xdef.hxx> |
123 | | #include <editeng/lrspitem.hxx> // Defines SvxLRSpaceItem |
124 | | #include <editeng/ulspitem.hxx> // Defines SvxULSpaceItem |
125 | | #include <sfx2/lokhelper.hxx> |
126 | | |
127 | | using namespace ::com::sun::star; |
128 | | |
129 | | void ScDocShell::SetInitialLinkUpdate( const SfxMedium* pMed ) |
130 | 17.9k | { |
131 | 17.9k | if (pMed) |
132 | 17.9k | { |
133 | 17.9k | const SfxUInt16Item* pUpdateDocItem = pMed->GetItemSet().GetItem(SID_UPDATEDOCMODE, false); |
134 | 17.9k | m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE; |
135 | 17.9k | } |
136 | | |
137 | | // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have |
138 | | // been set first. Do not override an already forbidden LinkUpdate (the |
139 | | // default is allow). |
140 | 17.9k | comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer(); |
141 | 17.9k | if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate()) |
142 | 17.9k | { |
143 | | // For anything else than LM_ALWAYS we need user confirmation. |
144 | 17.9k | rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS); |
145 | 17.9k | } |
146 | 17.9k | } |
147 | | |
148 | | ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const |
149 | 17.9k | { |
150 | 17.9k | ScLkUpdMode nSet; |
151 | 17.9k | if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE) |
152 | 17.9k | nSet = LM_NEVER; |
153 | 0 | else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE) |
154 | 0 | nSet = LM_ALWAYS; |
155 | 0 | else |
156 | 0 | { |
157 | 0 | nSet = GetDocument().GetLinkMode(); |
158 | 0 | if (nSet == LM_UNKNOWN) |
159 | 0 | { |
160 | 0 | ScAppOptions aAppOptions = ScModule::get()->GetAppOptions(); |
161 | 0 | nSet = aAppOptions.GetLinkMode(); |
162 | 0 | } |
163 | 0 | } |
164 | | |
165 | 17.9k | if (nSet != LM_NEVER |
166 | 0 | && (SvtSecurityOptions::isUntrustedReferer( |
167 | 0 | GetMedium() == nullptr ? OUString() : GetMedium()->GetName()) |
168 | 0 | || (IsDocShared() && SvtSecurityOptions::isUntrustedReferer(GetSharedFileURL())))) |
169 | 0 | { |
170 | 0 | nSet = LM_NEVER; |
171 | 0 | } |
172 | 17.9k | else if (nSet == LM_ALWAYS |
173 | 0 | && !(IsTrustedLocationForUpdatingLinks() |
174 | 0 | || (IsDocShared() |
175 | 0 | && SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( |
176 | 0 | GetSharedFileURL())))) |
177 | 0 | { |
178 | 0 | nSet = LM_ON_DEMAND; |
179 | 0 | } |
180 | 17.9k | if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE |
181 | 0 | && nSet == LM_ON_DEMAND) |
182 | 0 | { |
183 | 0 | nSet = LM_NEVER; |
184 | 0 | } |
185 | | |
186 | 17.9k | return nSet; |
187 | 17.9k | } |
188 | | |
189 | | void ScDocShell::AllowLinkUpdate() |
190 | 0 | { |
191 | 0 | m_pDocument->SetLinkFormulaNeedingCheck(false); |
192 | 0 | getEmbeddedObjectContainer().setUserAllowsLinkUpdate(true); |
193 | 0 | } |
194 | | |
195 | | void ScDocShell::ReloadAllLinks() |
196 | 0 | { |
197 | 0 | AllowLinkUpdate(); |
198 | |
|
199 | 0 | ReloadTabLinks(); |
200 | 0 | weld::Window *pDialogParent = GetActiveDialogParent(); |
201 | 0 | m_pDocument->UpdateExternalRefLinks(pDialogParent); |
202 | |
|
203 | 0 | bool bAnyDde = m_pDocument->GetDocLinkManager().updateDdeOrOleOrWebServiceLinks(pDialogParent); |
204 | |
|
205 | 0 | if (bAnyDde) |
206 | 0 | { |
207 | | // calculate formulas and paint like in the TrackTimeHdl |
208 | 0 | m_pDocument->TrackFormulas(); |
209 | 0 | Broadcast(SfxHint(SfxHintId::ScDataChanged)); |
210 | | |
211 | | // Should FID_DATACHANGED become asynchronous some time |
212 | | // (e.g., with Invalidate at Window), an update needs to be forced here. |
213 | 0 | } |
214 | |
|
215 | 0 | m_pDocument->UpdateAreaLinks(); |
216 | | |
217 | | // Draw-layer fill bitmap host links are registered when SID_UPDATETABLINKS |
218 | | // runs at load, so they are not re-scanned here, only updated. |
219 | 0 | if (sfx2::LinkManager* pLinkMgr = m_pDocument->GetDocLinkManager().getLinkManager(false)) |
220 | 0 | { |
221 | 0 | registerDeferredFormImageLinks(GetDeferredFormControlImages(), *pLinkMgr); |
222 | 0 | ClearDeferredFormControlImages(); |
223 | 0 | pLinkMgr->UpdateAllLinks(false, u""_ustr); |
224 | 0 | } |
225 | 0 | } |
226 | | |
227 | | void ScDocShell::PerformLinkUpdate() |
228 | 0 | { |
229 | 0 | ScDocument& rDoc = GetDocument(); |
230 | 0 | if (rDoc.HasLinkFormulaNeedingCheck() && rDoc.GetDocLinkManager().hasExternalRefLinks()) |
231 | 0 | { |
232 | | // If we have WEBSERVICE/Dde link and other external links in the document, it might indicate some |
233 | | // exfiltration attempt, add *another* warning about this on top of the "Security Warning" |
234 | | // shown in the infobar before they got here. |
235 | 0 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetActiveDialogParent(), |
236 | 0 | VclMessageType::Warning, VclButtonsType::YesNo, |
237 | 0 | ScResId(STR_TRUST_DOCUMENT_WARNING))); |
238 | 0 | xQueryBox->set_secondary_text(ScResId(STR_WEBSERVICE_WITH_LINKS_WARNING)); |
239 | 0 | xQueryBox->set_default_response(RET_NO); |
240 | 0 | if (xQueryBox->run() != RET_YES) |
241 | 0 | return; |
242 | 0 | } |
243 | | |
244 | 0 | ReloadAllLinks(); |
245 | 0 | } |
246 | | |
247 | | bool ScDocShell::HasExternalLinks() const |
248 | 0 | { |
249 | 0 | return GetDocument().HasExternalLinks() || !GetDeferredFormControlImages().empty() |
250 | 0 | || HasExternalDatabaseForms(); |
251 | 0 | } |
252 | | |
253 | | namespace |
254 | | { |
255 | | |
256 | | void lcl_setLOKLocale(const ScTabViewShell& rViewShell, const LanguageType eLang) |
257 | 0 | { |
258 | 0 | OUString aLang = LanguageTag(eLang).getBcp47(); |
259 | | /// This is only used for building the lok calendar as of date. |
260 | | /// Don't change the view language as it affects the js-dialog language as well. |
261 | 0 | SfxLokHelper::setViewLocale(SfxLokHelper::getView(rViewShell), aLang); |
262 | 0 | } |
263 | | |
264 | | } // end anonymous namespace |
265 | | |
266 | | void ScDocShell::SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl) |
267 | 0 | { |
268 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
269 | 0 | { |
270 | 0 | if (ScTabViewShell* pViewShell = GetBestViewShell()) |
271 | 0 | { |
272 | 0 | lcl_setLOKLocale(*pViewShell, eLatin); |
273 | 0 | } |
274 | 0 | } |
275 | | |
276 | | // Update the document language even in lok mode as |
277 | | // the spell-check is still based on document language. |
278 | 0 | GetDocument().SetLanguage(eLatin, eCjk, eCtl); |
279 | 0 | } |
280 | | |
281 | | void ScDocShell::Execute( SfxRequest& rReq ) |
282 | 0 | { |
283 | 0 | const SfxItemSet* pReqArgs = rReq.GetArgs(); |
284 | 0 | SfxBindings* pBindings = GetViewBindings(); |
285 | 0 | bool bUndo (m_pDocument->IsUndoEnabled()); |
286 | |
|
287 | 0 | sal_uInt16 nSlot = rReq.GetSlot(); |
288 | 0 | switch ( nSlot ) |
289 | 0 | { |
290 | 0 | case SID_SC_SETTEXT: |
291 | 0 | { |
292 | 0 | const SfxPoolItem* pColItem; |
293 | 0 | const SfxPoolItem* pRowItem; |
294 | 0 | const SfxPoolItem* pTabItem; |
295 | 0 | const SfxPoolItem* pTextItem; |
296 | 0 | if( pReqArgs && pReqArgs->HasItem( FN_PARAM_1, &pColItem ) && |
297 | 0 | pReqArgs->HasItem( FN_PARAM_2, &pRowItem ) && |
298 | 0 | pReqArgs->HasItem( FN_PARAM_3, &pTabItem ) && |
299 | 0 | pReqArgs->HasItem( SID_SC_SETTEXT, &pTextItem ) ) |
300 | 0 | { |
301 | | // parameters are 1-based !!! |
302 | 0 | SCCOL nCol = static_cast<const SfxInt16Item*>(pColItem)->GetValue() - 1; |
303 | 0 | SCROW nRow = static_cast<const SfxInt32Item*>(pRowItem)->GetValue() - 1; |
304 | 0 | SCTAB nTab = static_cast<const SfxInt16Item*>(pTabItem)->GetValue() - 1; |
305 | |
|
306 | 0 | SCTAB nTabCount = m_pDocument->GetTableCount(); |
307 | 0 | if ( m_pDocument->ValidCol(nCol) && m_pDocument->ValidRow(nRow) && ValidTab(nTab,nTabCount) ) |
308 | 0 | { |
309 | 0 | if ( m_pDocument->IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) ) |
310 | 0 | { |
311 | 0 | OUString aVal = static_cast<const SfxStringItem*>(pTextItem)->GetValue(); |
312 | 0 | m_pDocument->SetString( nCol, nRow, nTab, aVal ); |
313 | |
|
314 | 0 | PostPaintCell( nCol, nRow, nTab ); |
315 | 0 | SetDocumentModified(); |
316 | |
|
317 | 0 | rReq.Done(); |
318 | 0 | break; |
319 | 0 | } |
320 | 0 | else // protected cell |
321 | 0 | { |
322 | | #if HAVE_FEATURE_SCRIPTING |
323 | | SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER ); //! which error ? |
324 | | #endif |
325 | 0 | break; |
326 | 0 | } |
327 | 0 | } |
328 | 0 | } |
329 | | #if HAVE_FEATURE_SCRIPTING |
330 | | SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); |
331 | | #endif |
332 | 0 | } |
333 | 0 | break; |
334 | | |
335 | 0 | case SID_SBA_IMPORT: |
336 | 0 | { |
337 | 0 | if (pReqArgs) |
338 | 0 | { |
339 | 0 | const SfxPoolItem* pItem; |
340 | 0 | svx::ODataAccessDescriptor aDesc; |
341 | 0 | if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET ) |
342 | 0 | { |
343 | 0 | uno::Any aAny = static_cast<const SfxUnoAnyItem*>(pItem)->GetValue(); |
344 | 0 | uno::Sequence<beans::PropertyValue> aProperties; |
345 | 0 | if ( aAny >>= aProperties ) |
346 | 0 | aDesc.initializeFrom( aProperties ); |
347 | 0 | } |
348 | |
|
349 | 0 | OUString sTarget; |
350 | 0 | if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET ) |
351 | 0 | sTarget = static_cast<const SfxStringItem*>(pItem)->GetValue(); |
352 | |
|
353 | 0 | bool bIsNewArea = true; // Default sal_True (no inquiry) |
354 | 0 | if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET ) |
355 | 0 | bIsNewArea = static_cast<const SfxBoolItem*>(pItem)->GetValue(); |
356 | | |
357 | | // if necessary, create new database area |
358 | 0 | bool bMakeArea = false; |
359 | 0 | if (bIsNewArea) |
360 | 0 | { |
361 | 0 | ScDBCollection* pDBColl = m_pDocument->GetDBCollection(); |
362 | 0 | if ( !pDBColl || !pDBColl->getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(sTarget)) ) |
363 | 0 | { |
364 | 0 | ScAddress aPos; |
365 | 0 | if ( aPos.Parse( sTarget, *m_pDocument, m_pDocument->GetAddressConvention() ) & ScRefFlags::VALID ) |
366 | 0 | { |
367 | 0 | bMakeArea = true; |
368 | 0 | if (bUndo) |
369 | 0 | { |
370 | 0 | OUString aStrImport = ScResId( STR_UNDO_IMPORTDATA ); |
371 | 0 | ViewShellId nViewShellId(-1); |
372 | 0 | if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) |
373 | 0 | nViewShellId = pViewSh->GetViewShellId(); |
374 | 0 | GetUndoManager()->EnterListAction( aStrImport, aStrImport, 0, nViewShellId ); |
375 | 0 | } |
376 | |
|
377 | 0 | ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, ScGetDBSelection::Keep ); |
378 | 0 | assert(pDBData && "Cannot create DB data"); |
379 | 0 | sTarget = pDBData->GetName(); |
380 | 0 | } |
381 | 0 | } |
382 | 0 | } |
383 | | |
384 | | // inquire, before old DB range gets overwritten |
385 | 0 | bool bDo = true; |
386 | 0 | if (!bIsNewArea) |
387 | 0 | { |
388 | 0 | OUString aTemplate = ScResId( STR_IMPORT_REPLACE ); |
389 | 0 | OUString aMessage = o3tl::getToken(aTemplate, 0, '#' ) |
390 | 0 | + sTarget |
391 | 0 | + o3tl::getToken(aTemplate, 1, '#' ); |
392 | |
|
393 | 0 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr, |
394 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
395 | 0 | aMessage)); |
396 | 0 | xQueryBox->set_default_response(RET_YES); |
397 | 0 | bDo = xQueryBox->run() == RET_YES; |
398 | 0 | } |
399 | |
|
400 | 0 | if (bDo) |
401 | 0 | { |
402 | 0 | ScDBDocFunc(*this).UpdateImport( sTarget, aDesc ); |
403 | 0 | rReq.Done(); |
404 | | |
405 | | // UpdateImport also updates the internal operations |
406 | 0 | } |
407 | 0 | else |
408 | 0 | rReq.Ignore(); |
409 | |
|
410 | 0 | if ( bMakeArea && bUndo) |
411 | 0 | GetUndoManager()->LeaveListAction(); |
412 | 0 | } |
413 | 0 | else |
414 | 0 | { |
415 | 0 | OSL_FAIL( "arguments expected" ); |
416 | 0 | } |
417 | 0 | } |
418 | 0 | break; |
419 | | |
420 | 0 | case SID_CHART_SOURCE: |
421 | 0 | case SID_CHART_ADDSOURCE: |
422 | 0 | ExecuteChartSource(rReq); |
423 | 0 | break; |
424 | | |
425 | 0 | case FID_AUTO_CALC: |
426 | 0 | { |
427 | 0 | bool bNewVal; |
428 | 0 | const SfxPoolItem* pItem; |
429 | 0 | if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) ) |
430 | 0 | bNewVal = static_cast<const SfxBoolItem*>(pItem)->GetValue(); |
431 | 0 | else |
432 | 0 | bNewVal = !m_pDocument->GetAutoCalc(); // Toggle for menu |
433 | 0 | m_pDocument->SetAutoCalc( bNewVal ); |
434 | 0 | SetDocumentModified(); |
435 | 0 | if (pBindings) |
436 | 0 | { |
437 | 0 | pBindings->Invalidate( FID_AUTO_CALC ); |
438 | 0 | } |
439 | 0 | rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) ); |
440 | 0 | rReq.Done(); |
441 | 0 | } |
442 | 0 | break; |
443 | 0 | case SID_OPEN_HYPERLINK: |
444 | 0 | { |
445 | 0 | ScViewData* pViewData = GetViewData(); |
446 | 0 | if ( !pViewData ) |
447 | 0 | { |
448 | 0 | rReq.Ignore(); |
449 | 0 | break; |
450 | 0 | } |
451 | | |
452 | 0 | if (ScModule::get()->IsEditMode()) |
453 | 0 | { |
454 | 0 | if (EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart())) |
455 | 0 | { |
456 | 0 | const SvxFieldItem* pFieldItem = pEditView->GetFieldAtSelection(/*bAlsoCheckBeforeCursor=*/true); |
457 | 0 | const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : nullptr; |
458 | 0 | if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField)) |
459 | 0 | { |
460 | 0 | ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame(), true); |
461 | 0 | rReq.Done(); |
462 | 0 | break; |
463 | 0 | } |
464 | 0 | } |
465 | 0 | } |
466 | 0 | else |
467 | 0 | { |
468 | 0 | if (ScGridWindow* pWin = pViewData->GetActiveWin()) |
469 | 0 | { |
470 | 0 | std::vector<UrlData> vUrls = pWin->GetEditUrls(pViewData->GetCurPos()); |
471 | 0 | if (!vUrls.empty()) |
472 | 0 | { |
473 | 0 | for (UrlData& data : vUrls) |
474 | 0 | { |
475 | 0 | ScGlobal::OpenURL(data.aUrl, data.aTarget, true); |
476 | 0 | } |
477 | 0 | rReq.Done(); |
478 | 0 | break; |
479 | 0 | } |
480 | 0 | } |
481 | 0 | } |
482 | 0 | rReq.Ignore(); |
483 | 0 | } |
484 | 0 | break; |
485 | 0 | case FID_RECALC: |
486 | 0 | DoRecalc( rReq.IsAPI() ); |
487 | 0 | rReq.Done(); |
488 | 0 | break; |
489 | 0 | case FID_HARD_RECALC: |
490 | 0 | DoHardRecalc(); |
491 | 0 | rReq.Done(); |
492 | 0 | break; |
493 | 0 | case SID_UPDATETABLINKS: |
494 | 0 | { |
495 | | // Draw-layer fill bitmap links are registered as the shapes are |
496 | | // imported, via the draw model's link tracker. Form control |
497 | | // images are collected during import and registered here. |
498 | 0 | if (sfx2::LinkManager* pLinkMgr = m_pDocument->GetDocLinkManager().getLinkManager(false)) |
499 | 0 | { |
500 | 0 | registerDeferredFormImageLinks(GetDeferredFormControlImages(), *pLinkMgr); |
501 | 0 | ClearDeferredFormControlImages(); |
502 | 0 | } |
503 | |
|
504 | 0 | ScLkUpdMode nSet = GetLinkUpdateModeState(); |
505 | |
|
506 | 0 | if (nSet == LM_ALWAYS) |
507 | 0 | { |
508 | 0 | ReloadAllLinks(); |
509 | 0 | rReq.Done(); |
510 | 0 | } |
511 | 0 | else if (nSet == LM_NEVER) |
512 | 0 | { |
513 | 0 | getEmbeddedObjectContainer().setUserAllowsLinkUpdate(false); |
514 | 0 | CheckPendingLinkUpdateInfobar(); |
515 | 0 | rReq.Ignore(); |
516 | 0 | } |
517 | 0 | else if (nSet == LM_ON_DEMAND) |
518 | 0 | { |
519 | 0 | ShowLinkUpdateInfobar(); |
520 | 0 | rReq.Done(); |
521 | 0 | } |
522 | 0 | } |
523 | 0 | break; |
524 | | |
525 | 0 | case SID_REIMPORT_AFTER_LOAD: |
526 | 0 | { |
527 | | // Is called after loading if there are DB areas with omitted data |
528 | |
|
529 | 0 | bool bDone = false; |
530 | 0 | ScDBCollection* pDBColl = m_pDocument->GetDBCollection(); |
531 | |
|
532 | 0 | if ((m_nCanUpdate != css::document::UpdateDocMode::NO_UPDATE) && |
533 | 0 | (m_nCanUpdate != css::document::UpdateDocMode::QUIET_UPDATE)) |
534 | 0 | { |
535 | 0 | ScRange aRange; |
536 | 0 | ScTabViewShell* pViewSh = GetBestViewShell(); |
537 | 0 | OSL_ENSURE(pViewSh,"SID_REIMPORT_AFTER_LOAD: no View"); |
538 | 0 | if (pViewSh && pDBColl) |
539 | 0 | { |
540 | 0 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetActiveDialogParent(), |
541 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
542 | 0 | ScResId(STR_REIMPORT_AFTER_LOAD))); |
543 | 0 | xQueryBox->set_default_response(RET_YES); |
544 | 0 | if (xQueryBox->run() == RET_YES) |
545 | 0 | { |
546 | 0 | ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs(); |
547 | 0 | for (const auto& rxDB : rDBs) |
548 | 0 | { |
549 | 0 | ScDBData& rDBData = *rxDB; |
550 | 0 | if ( rDBData.IsStripData() && |
551 | 0 | rDBData.HasImportParam() && !rDBData.HasImportSelection() ) |
552 | 0 | { |
553 | 0 | rDBData.GetArea(aRange); |
554 | 0 | pViewSh->MarkRange(aRange); |
555 | | |
556 | | // Import and internal operations like SID_REFRESH_DBAREA |
557 | | // (inquiry for import not needed here) |
558 | |
|
559 | 0 | ScImportParam aImportParam; |
560 | 0 | rDBData.GetImportParam( aImportParam ); |
561 | 0 | bool bContinue = pViewSh->ImportData( aImportParam ); |
562 | 0 | rDBData.SetImportParam( aImportParam ); |
563 | | |
564 | | // mark (size may have changed) |
565 | 0 | rDBData.GetArea(aRange); |
566 | 0 | pViewSh->MarkRange(aRange); |
567 | |
|
568 | 0 | if ( bContinue ) // error at import -> abort |
569 | 0 | { |
570 | | // internal operations, if some were saved |
571 | |
|
572 | 0 | if ( rDBData.HasQueryParam() || rDBData.HasSortParam() || |
573 | 0 | rDBData.HasSubTotalParam() ) |
574 | 0 | pViewSh->RepeatDB(); |
575 | | |
576 | | // pivot tables, which have the range as source data |
577 | |
|
578 | 0 | RefreshPivotTables(aRange); |
579 | 0 | } |
580 | 0 | } |
581 | 0 | } |
582 | 0 | bDone = true; |
583 | 0 | } |
584 | 0 | } |
585 | 0 | } |
586 | |
|
587 | 0 | if ( !bDone && pDBColl ) |
588 | 0 | { |
589 | | // if not, but then update the dependent formulas |
590 | | //! also for individual ranges, which cannot be updated |
591 | |
|
592 | 0 | m_pDocument->CalcAll(); //! only for the dependent |
593 | 0 | PostDataChanged(); |
594 | 0 | } |
595 | |
|
596 | 0 | if (bDone) |
597 | 0 | rReq.Done(); |
598 | 0 | else |
599 | 0 | rReq.Ignore(); |
600 | 0 | } |
601 | 0 | break; |
602 | | |
603 | 0 | case SID_ATTR_PAGE_ORIENTATION: // .uno:Orientation |
604 | 0 | { |
605 | 0 | const SfxBoolItem* pBool = rReq.GetArg<SfxBoolItem>(SID_ATTR_PAGE_ORIENTATION); |
606 | |
|
607 | 0 | if (!pBool) // nothing supplied -> do nothing |
608 | 0 | { |
609 | 0 | rReq.Done(); |
610 | 0 | break; |
611 | 0 | } |
612 | 0 | ScViewData* pViewData = GetViewData(); |
613 | 0 | if (!pViewData) |
614 | 0 | break; |
615 | | |
616 | 0 | ScDocument& rDoc = GetDocument(); |
617 | 0 | const SCTAB nTab = pViewData->CurrentTabForData(); |
618 | | |
619 | | // obtain the page-style’s ItemSet |
620 | 0 | OUString aStyleName = rDoc.GetPageStyle(nTab); |
621 | 0 | ScStyleSheetPool* pPagePool = rDoc.GetStyleSheetPool(); |
622 | 0 | if (!pPagePool) |
623 | 0 | break; |
624 | 0 | SfxStyleSheetBase* pStyle = pPagePool->Find(aStyleName, SfxStyleFamily::Page); |
625 | 0 | if (!pStyle) |
626 | 0 | break; |
627 | | |
628 | 0 | SfxItemSet& rSet = pStyle->GetItemSet(); |
629 | |
|
630 | 0 | const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE); |
631 | 0 | const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE); |
632 | |
|
633 | 0 | bool bDesiredLandscape = pBool->GetValue(); |
634 | 0 | bool bCurrentLandscape = rOldPageItem.IsLandscape(); |
635 | |
|
636 | 0 | if (bDesiredLandscape == bCurrentLandscape) // already correct |
637 | 0 | { |
638 | 0 | rReq.Done(); |
639 | 0 | break; |
640 | 0 | } |
641 | | // apply the change: flip orientation and swap paper size |
642 | 0 | SvxPageItem aNewPageItem(ATTR_PAGE); |
643 | 0 | aNewPageItem.SetLandscape(bDesiredLandscape); |
644 | |
|
645 | 0 | Size aOld = rOldSizeItem.GetSize(); |
646 | | // coverity[swapped_arguments : FALSE] - this is in the correct order |
647 | 0 | Size aNew(aOld.Height(), aOld.Width()); // swap W/H |
648 | 0 | SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNew); |
649 | |
|
650 | 0 | rSet.Put(aNewPageItem); |
651 | 0 | rSet.Put(aNewSizeItem); |
652 | |
|
653 | 0 | SetDocumentModified(); |
654 | 0 | PostPaintGridAll(); // repaint sheet |
655 | |
|
656 | 0 | if (pBindings) { |
657 | |
|
658 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION); |
659 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_SIZE); |
660 | 0 | } |
661 | |
|
662 | 0 | rReq.Done(); |
663 | 0 | } |
664 | 0 | break; |
665 | 0 | case SID_SC_ATTR_PAGE_SIZE: |
666 | 0 | { |
667 | 0 | const SfxUInt16Item* pPaperFormatInt |
668 | 0 | = rReq.GetArg<SfxUInt16Item>(SID_SC_ATTR_PAGE_SIZE); |
669 | 0 | if (!pPaperFormatInt) |
670 | 0 | break; |
671 | | |
672 | 0 | Paper ePaper = static_cast<Paper>(pPaperFormatInt->GetValue()); |
673 | 0 | if (ePaper >= NUM_PAPER_ENTRIES |
674 | 0 | && ePaper != PAPER_USER) // PAPER_USER is a valid special case |
675 | 0 | { |
676 | 0 | break; |
677 | 0 | } |
678 | | |
679 | 0 | Size aNewSize = SvxPaperInfo::GetPaperSize(ePaper); |
680 | |
|
681 | 0 | ScViewData* pViewData = GetViewData(); |
682 | 0 | if (!pViewData) |
683 | 0 | break; |
684 | 0 | ScDocument& rDoc = GetDocument(); |
685 | 0 | const SCTAB nTab = pViewData->CurrentTabForData(); |
686 | 0 | OUString aStyleName = rDoc.GetPageStyle(nTab); |
687 | 0 | ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); |
688 | 0 | SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page); |
689 | 0 | if (!pStyleSheet) |
690 | 0 | break; |
691 | | |
692 | 0 | SfxItemSet& rSet = pStyleSheet->GetItemSet(); |
693 | 0 | const SvxSizeItem& rOldSizeItem = rSet.Get(ATTR_PAGE_SIZE); |
694 | | |
695 | | // Only apply if the size is actually different |
696 | 0 | if (aNewSize == rOldSizeItem.GetSize()) |
697 | 0 | { |
698 | 0 | rReq.Done(); |
699 | 0 | break; |
700 | 0 | } |
701 | | |
702 | 0 | SvxSizeItem aNewSizeItem(ATTR_PAGE_SIZE, aNewSize); |
703 | 0 | rSet.Put(aNewSizeItem); |
704 | | |
705 | | // Also update the orientation flag to be consistent with the new dimensions |
706 | 0 | const SvxPageItem& rOldPageItem = rSet.Get(ATTR_PAGE); |
707 | 0 | bool bNewIsLandscape = aNewSize.Width() > aNewSize.Height(); |
708 | 0 | if (bNewIsLandscape != rOldPageItem.IsLandscape()) |
709 | 0 | { |
710 | 0 | SvxPageItem aNewPageItem(ATTR_PAGE); |
711 | 0 | aNewPageItem.SetLandscape(bNewIsLandscape); |
712 | 0 | rSet.Put(aNewPageItem); |
713 | 0 | } |
714 | |
|
715 | 0 | SetDocumentModified(); |
716 | 0 | PostPaintGridAll(); |
717 | |
|
718 | 0 | if (pBindings) |
719 | 0 | { |
720 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_SIZE); |
721 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION); |
722 | 0 | } |
723 | |
|
724 | 0 | rReq.Done(); |
725 | 0 | } |
726 | 0 | break; |
727 | 0 | case SID_SC_ATTR_PAGE_MARGIN: |
728 | 0 | { |
729 | 0 | const SvxLRSpaceItem* pLR = rReq.GetArg(SID_ATTR_LRSPACE); |
730 | 0 | if (!pLR) { |
731 | 0 | SAL_WARN( "sc", " Left & Right margins are missing"); |
732 | 0 | break; |
733 | 0 | } |
734 | | |
735 | 0 | SvxIndentValue nLeft = pLR->GetLeft(); |
736 | 0 | SvxIndentValue nRight = pLR->GetRight(); |
737 | |
|
738 | 0 | const SvxULSpaceItem* pUL = rReq.GetArg(SID_ATTR_ULSPACE); |
739 | 0 | if (!pUL) { |
740 | 0 | SAL_WARN( "sc", " Top & Bottom margins are missing"); |
741 | 0 | break; |
742 | 0 | } |
743 | 0 | long nTop = pUL->GetUpper(); |
744 | 0 | long nBottom = pUL->GetLower(); |
745 | |
|
746 | 0 | ScViewData* pViewData = GetViewData(); |
747 | 0 | if (!pViewData) |
748 | 0 | { |
749 | 0 | break; |
750 | 0 | } |
751 | | |
752 | 0 | ScDocument& rDoc = GetDocument(); |
753 | 0 | const SCTAB nTab = pViewData->CurrentTabForData(); |
754 | 0 | OUString aStyleName = rDoc.GetPageStyle(nTab); |
755 | 0 | ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); |
756 | 0 | SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page); |
757 | 0 | assert(pStyleSheet); |
758 | 0 | SfxItemSet& rSet = pStyleSheet->GetItemSet(); |
759 | |
|
760 | 0 | SvxLRSpaceItem aLRItem(ATTR_LRSPACE); |
761 | 0 | aLRItem.SetLeft(nLeft); |
762 | 0 | aLRItem.SetRight(nRight); |
763 | 0 | rSet.Put(aLRItem); |
764 | |
|
765 | 0 | SvxULSpaceItem aULItem(ATTR_ULSPACE); |
766 | 0 | aULItem.SetUpper(nTop); |
767 | 0 | aULItem.SetLower(nBottom); |
768 | 0 | rSet.Put(aULItem); |
769 | |
|
770 | 0 | SetDocumentModified(); |
771 | |
|
772 | 0 | PostPaintGridAll(); |
773 | |
|
774 | 0 | if (pBindings) |
775 | 0 | { |
776 | 0 | pBindings->Invalidate(SID_SC_ATTR_PAGE_MARGIN); |
777 | 0 | pBindings->Invalidate(SID_ATTR_LRSPACE); |
778 | 0 | pBindings->Invalidate(SID_ATTR_ULSPACE); |
779 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_SIZE); |
780 | 0 | pBindings->Invalidate(SID_ATTR_PAGE_ORIENTATION); |
781 | 0 | } |
782 | |
|
783 | 0 | rReq.Done(); |
784 | 0 | } |
785 | 0 | break; |
786 | 0 | case SID_AUTO_STYLE: |
787 | 0 | OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE"); |
788 | 0 | break; |
789 | 0 | case SID_GET_COLORLIST: |
790 | 0 | { |
791 | 0 | const SvxColorListItem* pColItem = GetItem(SID_COLOR_TABLE); |
792 | 0 | const XColorListRef& pList = pColItem->GetColorList(); |
793 | 0 | rReq.SetReturnValue(OfaXColorListItem(SID_GET_COLORLIST, pList)); |
794 | 0 | } |
795 | 0 | break; |
796 | | |
797 | 0 | case FID_CHG_RECORD: |
798 | 0 | { |
799 | 0 | ScDocument& rDoc = GetDocument(); |
800 | | // get argument (recorded macro) |
801 | 0 | const SfxBoolItem* pItem = rReq.GetArg(FID_CHG_RECORD); |
802 | 0 | bool bDo = true; |
803 | | |
804 | | // desired state |
805 | 0 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); |
806 | 0 | bool bActivateTracking = (pChangeTrack == nullptr); // toggle |
807 | 0 | if ( pItem ) |
808 | 0 | bActivateTracking = pItem->GetValue(); // from argument |
809 | |
|
810 | 0 | if ( !bActivateTracking ) |
811 | 0 | { |
812 | 0 | if ( !pItem ) |
813 | 0 | { |
814 | | // no dialog on playing the macro |
815 | 0 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(), |
816 | 0 | VclMessageType::Warning, VclButtonsType::YesNo, |
817 | 0 | ScResId(STR_END_REDLINING))); |
818 | 0 | xWarn->set_default_response(RET_NO); |
819 | 0 | bDo = (xWarn->run() == RET_YES ); |
820 | 0 | } |
821 | |
|
822 | 0 | if ( bDo ) |
823 | 0 | { |
824 | 0 | if (pChangeTrack) |
825 | 0 | { |
826 | 0 | if ( pChangeTrack->IsProtected() ) |
827 | 0 | bDo = ExecuteChangeProtectionDialog(); |
828 | 0 | } |
829 | 0 | if ( bDo ) |
830 | 0 | { |
831 | 0 | rDoc.EndChangeTracking(); |
832 | 0 | PostPaintGridAll(); |
833 | 0 | } |
834 | 0 | } |
835 | 0 | } |
836 | 0 | else |
837 | 0 | { |
838 | 0 | rDoc.StartChangeTracking(); |
839 | 0 | ScChangeViewSettings aChangeViewSet; |
840 | 0 | aChangeViewSet.SetShowChanges(true); |
841 | 0 | rDoc.SetChangeViewSettings(aChangeViewSet); |
842 | 0 | } |
843 | |
|
844 | 0 | if ( bDo ) |
845 | 0 | { |
846 | 0 | UpdateAcceptChangesDialog(); |
847 | | |
848 | | // invalidate slots |
849 | 0 | if (pBindings) |
850 | 0 | pBindings->InvalidateAll(false); |
851 | 0 | if ( !pItem ) |
852 | 0 | rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) ); |
853 | 0 | rReq.Done(); |
854 | 0 | } |
855 | 0 | else |
856 | 0 | rReq.Ignore(); |
857 | 0 | } |
858 | 0 | break; |
859 | | |
860 | 0 | case SID_CHG_PROTECT : |
861 | 0 | { |
862 | 0 | if ( ExecuteChangeProtectionDialog() ) |
863 | 0 | { |
864 | 0 | rReq.Done(); |
865 | 0 | SetDocumentModified(); |
866 | 0 | } |
867 | 0 | else |
868 | 0 | rReq.Ignore(); |
869 | 0 | } |
870 | 0 | break; |
871 | | |
872 | 0 | case SID_DOCUMENT_MERGE: |
873 | 0 | case SID_DOCUMENT_COMPARE: |
874 | 0 | { |
875 | 0 | bool bDo = true; |
876 | 0 | ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack(); |
877 | 0 | if ( pChangeTrack && !m_pImpl->bIgnoreLostRedliningWarning ) |
878 | 0 | { |
879 | 0 | if ( nSlot == SID_DOCUMENT_COMPARE ) |
880 | 0 | { //! old changes trace will be lost |
881 | 0 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetActiveDialogParent(), |
882 | 0 | VclMessageType::Warning, VclButtonsType::YesNo, |
883 | 0 | ScResId(STR_END_REDLINING))); |
884 | 0 | xWarn->set_default_response(RET_NO); |
885 | 0 | if (xWarn->run() == RET_YES) |
886 | 0 | bDo = ExecuteChangeProtectionDialog( true ); |
887 | 0 | else |
888 | 0 | bDo = false; |
889 | 0 | } |
890 | 0 | else // merge might reject some actions |
891 | 0 | bDo = ExecuteChangeProtectionDialog( true ); |
892 | 0 | } |
893 | 0 | if ( !bDo ) |
894 | 0 | { |
895 | 0 | rReq.Ignore(); |
896 | 0 | break; |
897 | 0 | } |
898 | 0 | SfxApplication* pApp = SfxGetpApp(); |
899 | 0 | const SfxPoolItem* pItem; |
900 | 0 | const SfxStringItem* pFileNameItem(nullptr); |
901 | 0 | SfxMedium* pMed = nullptr; |
902 | 0 | if (pReqArgs) |
903 | 0 | pFileNameItem = pReqArgs->GetItemIfSet(SID_FILE_NAME); |
904 | 0 | if (pFileNameItem) |
905 | 0 | { |
906 | 0 | OUString aFileName = pFileNameItem->GetValue(); |
907 | |
|
908 | 0 | OUString aFilterName; |
909 | 0 | if (const SfxStringItem* pFilterItem = pReqArgs->GetItemIfSet(SID_FILTER_NAME)) |
910 | 0 | { |
911 | 0 | aFilterName = pFilterItem->GetValue(); |
912 | 0 | } |
913 | 0 | OUString aOptions; |
914 | 0 | if (const SfxStringItem* pOptionsItem = pReqArgs->GetItemIfSet(SID_FILE_FILTEROPTIONS)) |
915 | 0 | { |
916 | 0 | aOptions = pOptionsItem->GetValue(); |
917 | 0 | } |
918 | 0 | short nVersion = 0; |
919 | 0 | const SfxInt16Item* pInt16Item(nullptr); |
920 | 0 | if (pReqArgs->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET) |
921 | 0 | pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem); |
922 | 0 | if (pInt16Item) |
923 | 0 | { |
924 | 0 | nVersion = pInt16Item->GetValue(); |
925 | 0 | } |
926 | | |
927 | | // no filter specified -> detection |
928 | 0 | if (aFilterName.isEmpty()) |
929 | 0 | ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, true, false ); |
930 | | |
931 | | // filter name from dialog contains application prefix, |
932 | | // GetFilter needs name without the prefix. |
933 | 0 | ScDocumentLoader::RemoveAppPrefix( aFilterName ); |
934 | |
|
935 | 0 | std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName ); |
936 | 0 | auto pSet = std::make_shared<SfxAllItemSet>( pApp->GetPool() ); |
937 | 0 | if (!aOptions.isEmpty()) |
938 | 0 | pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) ); |
939 | 0 | if ( nVersion != 0 ) |
940 | 0 | pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) ); |
941 | 0 | pMed = new SfxMedium( aFileName, StreamMode::STD_READ, std::move(pFilter), std::move(pSet) ); |
942 | 0 | } |
943 | 0 | else |
944 | 0 | { |
945 | 0 | const sfx2::DocumentInserter::Mode mode { nSlot==SID_DOCUMENT_COMPARE |
946 | 0 | ? sfx2::DocumentInserter::Mode::Compare |
947 | 0 | : sfx2::DocumentInserter::Mode::Merge}; |
948 | | // start file dialog asynchronous |
949 | 0 | m_pImpl->bIgnoreLostRedliningWarning = true; |
950 | 0 | m_pImpl->pRequest.reset(new SfxRequest( rReq )); |
951 | 0 | m_pImpl->pDocInserter.reset(); |
952 | |
|
953 | 0 | ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); |
954 | 0 | weld::Window* pParent = pViewSh ? pViewSh->GetFrameWeld() : nullptr; |
955 | 0 | m_pImpl->pDocInserter.reset( new ::sfx2::DocumentInserter(pParent, |
956 | 0 | ScDocShell::Factory().GetFactoryName(), mode ) ); |
957 | 0 | m_pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) ); |
958 | 0 | return ; |
959 | 0 | } |
960 | | |
961 | | // now execute in earnest... |
962 | 0 | SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() ); |
963 | | |
964 | | // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here |
965 | 0 | rtl::Reference<ScDocShell> pOtherDocSh = new ScDocShell; |
966 | 0 | pOtherDocSh->DoLoad( pMed ); |
967 | 0 | ErrCodeMsg nErr = pOtherDocSh->GetErrorCode(); |
968 | 0 | if (nErr) |
969 | 0 | ErrorHandler::HandleError( nErr ); // also warnings |
970 | |
|
971 | 0 | if ( !pOtherDocSh->GetErrorIgnoreWarning() ) // only errors |
972 | 0 | { |
973 | 0 | bool bHadTrack = ( m_pDocument->GetChangeTrack() != nullptr ); |
974 | | #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT |
975 | | sal_uLong nStart = 0; |
976 | | if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack ) |
977 | | { |
978 | | nStart = pChangeTrack->GetActionMax() + 1; |
979 | | } |
980 | | #endif |
981 | 0 | if ( nSlot == SID_DOCUMENT_COMPARE ) |
982 | 0 | CompareDocument( pOtherDocSh->GetDocument() ); |
983 | 0 | else |
984 | 0 | MergeDocument( pOtherDocSh->GetDocument() ); |
985 | | |
986 | | // show "accept changes" dialog |
987 | | //! get view for this document! |
988 | 0 | if ( !IsDocShared() ) |
989 | 0 | { |
990 | 0 | SfxViewFrame* pViewFrm = SfxViewFrame::Current(); |
991 | 0 | if ( pViewFrm ) |
992 | 0 | { |
993 | 0 | pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId() ); //@51669 |
994 | 0 | } |
995 | 0 | if ( pBindings ) |
996 | 0 | { |
997 | 0 | pBindings->Invalidate( FID_CHG_ACCEPT ); |
998 | 0 | } |
999 | 0 | } |
1000 | |
|
1001 | 0 | rReq.SetReturnValue( SfxInt32Item( TypedWhichId<SfxInt32Item>(nSlot), 0 ) ); //! ??????? |
1002 | 0 | rReq.Done(); |
1003 | |
|
1004 | 0 | if (!bHadTrack) // newly turned on -> show as well |
1005 | 0 | { |
1006 | 0 | ScChangeViewSettings* pOldSet = m_pDocument->GetChangeViewSettings(); |
1007 | 0 | if ( !pOldSet || !pOldSet->ShowChanges() ) |
1008 | 0 | { |
1009 | 0 | ScChangeViewSettings aChangeViewSet; |
1010 | 0 | aChangeViewSet.SetShowChanges(true); |
1011 | 0 | m_pDocument->SetChangeViewSettings(aChangeViewSet); |
1012 | 0 | } |
1013 | 0 | } |
1014 | | #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT |
1015 | | else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack ) |
1016 | | { |
1017 | | sal_uLong nEnd = pChangeTrack->GetActionMax(); |
1018 | | if ( nEnd >= nStart ) |
1019 | | { |
1020 | | // only show changes from merged document |
1021 | | ScChangeViewSettings aChangeViewSet; |
1022 | | aChangeViewSet.SetShowChanges( true ); |
1023 | | aChangeViewSet.SetShowAccepted( true ); |
1024 | | aChangeViewSet.SetHasActionRange(); |
1025 | | aChangeViewSet.SetTheActionRange( nStart, nEnd ); |
1026 | | m_pDocument->SetChangeViewSettings( aChangeViewSet ); |
1027 | | |
1028 | | // update view |
1029 | | PostPaintExtras(); |
1030 | | PostPaintGridAll(); |
1031 | | } |
1032 | | } |
1033 | | #endif |
1034 | 0 | } |
1035 | 0 | pOtherDocSh->DoClose(); // delete happens with the Ref |
1036 | 0 | } |
1037 | 0 | break; |
1038 | | |
1039 | 0 | case SID_DELETE_SCENARIO: |
1040 | 0 | if (pReqArgs) |
1041 | 0 | { |
1042 | 0 | const SfxPoolItem* pItem; |
1043 | 0 | if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET ) |
1044 | 0 | { |
1045 | 0 | if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem)) |
1046 | 0 | { |
1047 | 0 | const OUString& aName = pStringItem->GetValue(); |
1048 | 0 | SCTAB nTab; |
1049 | 0 | if (m_pDocument->GetTable( aName, nTab )) |
1050 | 0 | { |
1051 | | // move DeleteTable from viewfunc to docfunc! |
1052 | |
|
1053 | 0 | ScTabViewShell* pSh = GetBestViewShell(); |
1054 | 0 | if ( pSh ) |
1055 | 0 | { |
1056 | | //! omit SetTabNo in DeleteTable? |
1057 | 0 | SCTAB nDispTab = pSh->GetViewData().CurrentTabForData(); |
1058 | 0 | pSh->DeleteTable( nTab ); |
1059 | 0 | pSh->SetTabNo(nDispTab); |
1060 | 0 | rReq.Done(); |
1061 | 0 | } |
1062 | 0 | } |
1063 | 0 | } |
1064 | 0 | } |
1065 | 0 | } |
1066 | 0 | break; |
1067 | | |
1068 | 0 | case SID_EDIT_SCENARIO: |
1069 | 0 | { |
1070 | 0 | const SfxPoolItem* pItem; |
1071 | 0 | if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET ) |
1072 | 0 | { |
1073 | 0 | if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem)) |
1074 | 0 | { |
1075 | 0 | OUString aName = pStringItem->GetValue(); |
1076 | 0 | SCTAB nTab; |
1077 | 0 | if (m_pDocument->GetTable( aName, nTab )) |
1078 | 0 | { |
1079 | 0 | if (m_pDocument->IsScenario(nTab)) |
1080 | 0 | { |
1081 | 0 | OUString aComment; |
1082 | 0 | Color aColor; |
1083 | 0 | ScScenarioFlags nFlags; |
1084 | 0 | m_pDocument->GetScenarioData( nTab, aComment, aColor, nFlags ); |
1085 | | |
1086 | | // Determine if the Sheet that the Scenario was created on |
1087 | | // is protected. But first we need to find that Sheet. |
1088 | | // Rewind back to the actual sheet. |
1089 | 0 | SCTAB nActualTab = nTab; |
1090 | 0 | do |
1091 | 0 | { |
1092 | 0 | nActualTab--; |
1093 | 0 | } |
1094 | 0 | while(m_pDocument->IsScenario(nActualTab)); |
1095 | 0 | bool bSheetProtected = m_pDocument->IsTabProtected(nActualTab); |
1096 | |
|
1097 | 0 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); |
1098 | |
|
1099 | 0 | ScopedVclPtr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(GetActiveDialogParent(), aName, true, bSheetProtected)); |
1100 | 0 | pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags ); |
1101 | 0 | if ( pNewDlg->Execute() == RET_OK ) |
1102 | 0 | { |
1103 | 0 | pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags ); |
1104 | 0 | ModifyScenario( nTab, aName, aComment, aColor, nFlags ); |
1105 | 0 | rReq.Done(); |
1106 | 0 | } |
1107 | 0 | } |
1108 | 0 | } |
1109 | 0 | } |
1110 | 0 | } |
1111 | 0 | } |
1112 | 0 | break; |
1113 | | |
1114 | 0 | case SID_ATTR_YEAR2000 : |
1115 | 0 | { |
1116 | 0 | const SfxPoolItem* pItem; |
1117 | 0 | if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET ) |
1118 | 0 | { |
1119 | 0 | if (const SfxUInt16Item* pInt16Item = dynamic_cast<const SfxUInt16Item*>(pItem)) |
1120 | 0 | { |
1121 | 0 | sal_uInt16 nY2k = pInt16Item->GetValue(); |
1122 | | // set always to DocOptions, so that it is also saved for S050 |
1123 | | // (and all inquiries run up until now on it as well). |
1124 | | // SetDocOptions propagates that to the NumberFormatter |
1125 | 0 | ScDocOptions aDocOpt( m_pDocument->GetDocOptions() ); |
1126 | 0 | aDocOpt.SetYear2000( nY2k ); |
1127 | 0 | m_pDocument->SetDocOptions( aDocOpt ); |
1128 | | // the FormShell shall notice it as well |
1129 | 0 | ScTabViewShell* pSh = GetBestViewShell(); |
1130 | 0 | if ( pSh ) |
1131 | 0 | { |
1132 | 0 | FmFormShell* pFSh = pSh->GetFormShell(); |
1133 | 0 | if ( pFSh ) |
1134 | 0 | pFSh->SetY2KState( nY2k ); |
1135 | 0 | } |
1136 | 0 | } |
1137 | 0 | } |
1138 | 0 | } |
1139 | 0 | break; |
1140 | | |
1141 | | #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT |
1142 | | case SID_SHARE_DOC: |
1143 | | { |
1144 | | ScViewData* pViewData = GetViewData(); |
1145 | | if ( !pViewData ) |
1146 | | { |
1147 | | rReq.Ignore(); |
1148 | | break; |
1149 | | } |
1150 | | |
1151 | | weld::Window* pWin = GetActiveDialogParent(); |
1152 | | ScShareDocumentDlg aDlg(pWin, *pViewData); |
1153 | | if (aDlg.run() == RET_OK) |
1154 | | { |
1155 | | bool bSetShared = aDlg.IsShareDocumentChecked(); |
1156 | | if ( bSetShared != IsDocShared() ) |
1157 | | { |
1158 | | if ( bSetShared ) |
1159 | | { |
1160 | | bool bContinue = true; |
1161 | | if ( HasName() ) |
1162 | | { |
1163 | | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pWin, |
1164 | | VclMessageType::Question, VclButtonsType::YesNo, |
1165 | | ScResId(STR_DOC_WILLBESAVED))); |
1166 | | xQueryBox->set_default_response(RET_YES); |
1167 | | if (xQueryBox->run() == RET_NO) |
1168 | | { |
1169 | | bContinue = false; |
1170 | | } |
1171 | | } |
1172 | | if ( bContinue ) |
1173 | | { |
1174 | | EnableSharedSettings( true ); |
1175 | | |
1176 | | ScModule* mod = ScModule::get(); |
1177 | | mod->SetInSharedDocSaving(true); |
1178 | | if ( !SwitchToShared( true, true ) ) |
1179 | | { |
1180 | | // TODO/LATER: what should be done in case the switch has failed? |
1181 | | // for example in case the user has cancelled the saveAs operation |
1182 | | } |
1183 | | |
1184 | | mod->SetInSharedDocSaving(false); |
1185 | | |
1186 | | InvalidateName(); |
1187 | | GetUndoManager()->Clear(); |
1188 | | |
1189 | | ScTabView* pTabView = pViewData->GetView(); |
1190 | | if ( pTabView ) |
1191 | | { |
1192 | | pTabView->UpdateLayerLocks(); |
1193 | | } |
1194 | | } |
1195 | | } |
1196 | | else |
1197 | | { |
1198 | | uno::Reference< frame::XModel > xModel; |
1199 | | try |
1200 | | { |
1201 | | // load shared file |
1202 | | xModel.set( LoadSharedDocument(), uno::UNO_SET_THROW ); |
1203 | | uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW ); |
1204 | | |
1205 | | // check if shared flag is set in shared file |
1206 | | bool bShared = false; |
1207 | | ScModelObj* pDocObj = comphelper::getFromUnoTunnel<ScModelObj>( xModel ); |
1208 | | if ( pDocObj ) |
1209 | | { |
1210 | | ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() ); |
1211 | | if ( pDocShell ) |
1212 | | { |
1213 | | bShared = pDocShell->HasSharedXMLFlagSet(); |
1214 | | } |
1215 | | } |
1216 | | |
1217 | | // #i87870# check if shared status was disabled and enabled again |
1218 | | bool bOwnEntry = false; |
1219 | | try |
1220 | | { |
1221 | | ::svt::ShareControlFile aControlFile( GetSharedFileURL() ); |
1222 | | bOwnEntry = aControlFile.HasOwnEntry(); |
1223 | | } |
1224 | | catch ( uno::Exception& ) |
1225 | | { |
1226 | | } |
1227 | | |
1228 | | if ( bShared && bOwnEntry ) |
1229 | | { |
1230 | | uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW ); |
1231 | | if ( xStorable->isReadonly() ) |
1232 | | { |
1233 | | xCloseable->close( true ); |
1234 | | |
1235 | | OUString aUserName( ScResId( STR_UNKNOWN_USER ) ); |
1236 | | try |
1237 | | { |
1238 | | ::svt::DocumentLockFile aLockFile( GetSharedFileURL() ); |
1239 | | LockFileEntry aData = aLockFile.GetLockData(); |
1240 | | if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() ) |
1241 | | { |
1242 | | aUserName = aData[LockFileComponent::OOOUSERNAME]; |
1243 | | } |
1244 | | else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() ) |
1245 | | { |
1246 | | aUserName = aData[LockFileComponent::SYSUSERNAME]; |
1247 | | } |
1248 | | } |
1249 | | catch ( uno::Exception& ) |
1250 | | { |
1251 | | } |
1252 | | OUString aMessage( ScResId( STR_FILE_LOCKED_TRY_LATER ) ); |
1253 | | aMessage = aMessage.replaceFirst( "%1", aUserName ); |
1254 | | |
1255 | | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin, |
1256 | | VclMessageType::Warning, VclButtonsType::Ok, |
1257 | | aMessage)); |
1258 | | xWarn->run(); |
1259 | | } |
1260 | | else |
1261 | | { |
1262 | | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin, |
1263 | | VclMessageType::Warning, VclButtonsType::YesNo, |
1264 | | ScResId(STR_DOC_DISABLESHARED))); |
1265 | | xWarn->set_default_response(RET_YES); |
1266 | | |
1267 | | if (xWarn->run() == RET_YES) |
1268 | | { |
1269 | | xCloseable->close( true ); |
1270 | | |
1271 | | if ( !SwitchToShared( false, true ) ) |
1272 | | { |
1273 | | // TODO/LATER: what should be done in case the switch has failed? |
1274 | | // for example in case the user has cancelled the saveAs operation |
1275 | | } |
1276 | | |
1277 | | EnableSharedSettings( false ); |
1278 | | |
1279 | | // Do *not* use dispatch mechanism in this place - we don't want others (extensions etc.) to intercept this. |
1280 | | GetModel()->store(); |
1281 | | |
1282 | | ScTabView* pTabView = pViewData->GetView(); |
1283 | | if ( pTabView ) |
1284 | | { |
1285 | | pTabView->UpdateLayerLocks(); |
1286 | | } |
1287 | | } |
1288 | | else |
1289 | | { |
1290 | | xCloseable->close( true ); |
1291 | | } |
1292 | | } |
1293 | | } |
1294 | | else |
1295 | | { |
1296 | | xCloseable->close( true ); |
1297 | | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pWin, |
1298 | | VclMessageType::Warning, VclButtonsType::Ok, |
1299 | | ScResId(STR_DOC_NOLONGERSHARED))); |
1300 | | xWarn->run(); |
1301 | | } |
1302 | | } |
1303 | | catch ( uno::Exception& ) |
1304 | | { |
1305 | | TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" ); |
1306 | | ScModule::get()->SetInSharedDocSaving(false); |
1307 | | |
1308 | | try |
1309 | | { |
1310 | | uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); |
1311 | | xClose->close( true ); |
1312 | | } |
1313 | | catch ( uno::Exception& ) |
1314 | | { |
1315 | | } |
1316 | | } |
1317 | | } |
1318 | | } |
1319 | | } |
1320 | | rReq.Done(); |
1321 | | } |
1322 | | break; |
1323 | | #endif |
1324 | 0 | case SID_OPEN_CALC: |
1325 | 0 | { |
1326 | 0 | ScViewData* pViewData = GetViewData(); |
1327 | 0 | if (pViewData) |
1328 | 0 | { |
1329 | 0 | SfxStringItem aApp(SID_DOC_SERVICE, u"com.sun.star.sheet.SpreadsheetDocument"_ustr); |
1330 | 0 | SfxStringItem aTarget(SID_TARGETNAME, u"_blank"_ustr); |
1331 | 0 | pViewData->GetDispatcher().ExecuteList( |
1332 | 0 | SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON, |
1333 | 0 | { &aApp, &aTarget }); |
1334 | 0 | } |
1335 | 0 | } |
1336 | 0 | break; |
1337 | 0 | case SID_NOTEBOOKBAR: |
1338 | 0 | { |
1339 | 0 | const SfxStringItem* pFile = rReq.GetArg( SID_NOTEBOOKBAR ); |
1340 | |
|
1341 | 0 | if ( pBindings && sfx2::SfxNotebookBar::IsActive() ) |
1342 | 0 | sfx2::SfxNotebookBar::ExecMethod(*pBindings, pFile ? pFile->GetValue() : u""_ustr); |
1343 | 0 | else if ( pBindings ) |
1344 | 0 | sfx2::SfxNotebookBar::CloseMethod(*pBindings); |
1345 | 0 | } |
1346 | 0 | break; |
1347 | 0 | case SID_LANGUAGE_STATUS: |
1348 | 0 | { |
1349 | 0 | OUString aLangText; |
1350 | 0 | const SfxStringItem* pItem = rReq.GetArg<SfxStringItem>(nSlot); |
1351 | 0 | if ( pItem ) |
1352 | 0 | aLangText = pItem->GetValue(); |
1353 | |
|
1354 | 0 | if ( !aLangText.isEmpty() ) |
1355 | 0 | { |
1356 | 0 | LanguageType eLang, eLatin, eCjk, eCtl; |
1357 | 0 | static constexpr OUString aSelectionLangPrefix(u"Current_"_ustr); |
1358 | 0 | static constexpr OUString aParagraphLangPrefix(u"Paragraph_"_ustr); |
1359 | 0 | static constexpr OUString aDocLangPrefix(u"Default_"_ustr); |
1360 | |
|
1361 | 0 | bool bSelection = false; |
1362 | 0 | bool bParagraph = false; |
1363 | |
|
1364 | 0 | ScDocument& rDoc = GetDocument(); |
1365 | 0 | rDoc.GetLanguage( eLatin, eCjk, eCtl ); |
1366 | |
|
1367 | 0 | sal_Int32 nPos = 0; |
1368 | 0 | if ( aLangText == "*" ) |
1369 | 0 | { |
1370 | 0 | if (ScTabViewShell* pSh = GetBestViewShell()) |
1371 | 0 | { |
1372 | 0 | pSh->ExecuteCellFormatDlg(rReq, u"font"_ustr); |
1373 | 0 | pBindings->Invalidate(SID_LANGUAGE_STATUS); |
1374 | 0 | } |
1375 | 0 | } |
1376 | 0 | else if ( (nPos = aLangText.indexOf(aDocLangPrefix)) != -1 ) |
1377 | 0 | { |
1378 | 0 | aLangText = aLangText.replaceAt(nPos, aDocLangPrefix.getLength(), u""); |
1379 | |
|
1380 | 0 | if ( aLangText == "LANGUAGE_NONE" ) |
1381 | 0 | { |
1382 | 0 | eLang = LANGUAGE_NONE; |
1383 | 0 | SetLanguage(eLang, eCjk, eCtl); |
1384 | 0 | } |
1385 | 0 | else if ( aLangText == "RESET_LANGUAGES" ) |
1386 | 0 | { |
1387 | 0 | ScModule::GetSpellSettings(eLang, eCjk, eCtl); |
1388 | 0 | SetLanguage(eLang, eCjk, eCtl); |
1389 | 0 | } |
1390 | 0 | else |
1391 | 0 | { |
1392 | 0 | eLang = SvtLanguageTable::GetLanguageType( aLangText ); |
1393 | 0 | if ( eLang != LANGUAGE_DONTKNOW && SvtLanguageOptions::GetScriptTypeOfLanguage(eLang) == SvtScriptType::LATIN ) |
1394 | 0 | { |
1395 | 0 | SetLanguage(eLang, eCjk, eCtl); |
1396 | 0 | } |
1397 | 0 | else |
1398 | 0 | { |
1399 | 0 | eLang = eLatin; |
1400 | 0 | } |
1401 | 0 | } |
1402 | 0 | } |
1403 | 0 | else if (-1 != (nPos = aLangText.indexOf( aSelectionLangPrefix ))) |
1404 | 0 | { |
1405 | 0 | bSelection = true; |
1406 | 0 | aLangText = aLangText.replaceAt( nPos, aSelectionLangPrefix.getLength(), u"" ); |
1407 | 0 | } |
1408 | 0 | else if (-1 != (nPos = aLangText.indexOf( aParagraphLangPrefix ))) |
1409 | 0 | { |
1410 | 0 | bParagraph = true; |
1411 | 0 | aLangText = aLangText.replaceAt( nPos, aParagraphLangPrefix.getLength(), u"" ); |
1412 | 0 | } |
1413 | |
|
1414 | 0 | if (bSelection) |
1415 | 0 | { |
1416 | 0 | ScTabViewShell* pViewShell = GetBestViewShell(); |
1417 | 0 | if (pViewShell) |
1418 | 0 | { |
1419 | 0 | const ScPatternAttr* pSelAttrs = pViewShell->GetSelectionPattern(); |
1420 | 0 | if (pSelAttrs) |
1421 | 0 | { |
1422 | 0 | const SfxItemSet& rOldSet = pSelAttrs->GetItemSet(); |
1423 | 0 | SfxItemPool* pItemPool = rOldSet.GetPool(); |
1424 | 0 | auto pNewSet = std::make_shared<SfxItemSet>(*pItemPool); |
1425 | |
|
1426 | 0 | if (aLangText == "LANGUAGE_NONE") |
1427 | 0 | { |
1428 | 0 | pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE, |
1429 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE))); |
1430 | 0 | pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE, |
1431 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE))); |
1432 | 0 | pNewSet->Put(SvxLanguageItem(LANGUAGE_NONE, |
1433 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE))); |
1434 | 0 | } |
1435 | 0 | else |
1436 | 0 | { |
1437 | 0 | const LanguageType nLangType = SvtLanguageTable::GetLanguageType(aLangText); |
1438 | 0 | const SvtScriptType nScriptType = |
1439 | 0 | SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType); |
1440 | 0 | if (nScriptType == SvtScriptType::LATIN) |
1441 | 0 | pNewSet->Put(SvxLanguageItem(nLangType, |
1442 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE))); |
1443 | 0 | if (nScriptType == SvtScriptType::COMPLEX) |
1444 | 0 | pNewSet->Put(SvxLanguageItem(nLangType, |
1445 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE))); |
1446 | 0 | if (nScriptType == SvtScriptType::ASIAN) |
1447 | 0 | pNewSet->Put(SvxLanguageItem(nLangType, |
1448 | 0 | pItemPool->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE))); |
1449 | 0 | } |
1450 | 0 | pViewShell->ApplyAttributes(*pNewSet, rOldSet); |
1451 | 0 | pBindings->Invalidate(SID_LANGUAGE_STATUS); |
1452 | 0 | } |
1453 | 0 | } |
1454 | 0 | } |
1455 | 0 | else if (bParagraph) |
1456 | 0 | { |
1457 | 0 | ScViewData* pViewData = GetViewData(); |
1458 | 0 | if (!pViewData) |
1459 | 0 | return; |
1460 | | |
1461 | 0 | EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart()); |
1462 | 0 | if (!pEditView) |
1463 | 0 | return; |
1464 | | |
1465 | 0 | const LanguageType nLangToUse = SvtLanguageTable::GetLanguageType( aLangText ); |
1466 | 0 | SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse ); |
1467 | |
|
1468 | 0 | SfxItemSet aAttrs = pEditView->getEditEngine().GetEmptyItemSet(); |
1469 | 0 | if (nScriptType == SvtScriptType::LATIN) |
1470 | 0 | aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) ); |
1471 | 0 | if (nScriptType == SvtScriptType::COMPLEX) |
1472 | 0 | aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) ); |
1473 | 0 | if (nScriptType == SvtScriptType::ASIAN) |
1474 | 0 | aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) ); |
1475 | 0 | ESelection aOldSel; |
1476 | 0 | if (bParagraph) |
1477 | 0 | { |
1478 | 0 | ESelection aSel = pEditView->GetSelection(); |
1479 | 0 | aOldSel = aSel; |
1480 | 0 | aSel.start.nIndex = 0; |
1481 | 0 | aSel.end.nIndex = EE_TEXTPOS_MAX; |
1482 | 0 | pEditView->SetSelection( aSel ); |
1483 | 0 | } |
1484 | |
|
1485 | 0 | pEditView->SetAttribs( aAttrs ); |
1486 | 0 | if (bParagraph) |
1487 | 0 | pEditView->SetSelection( aOldSel ); |
1488 | 0 | } |
1489 | 0 | else if ( eLang != eLatin ) |
1490 | 0 | { |
1491 | 0 | if ( ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell() ) |
1492 | 0 | { |
1493 | 0 | ScInputHandler* pInputHandler = ScModule::get()->GetInputHdl(pViewSh); |
1494 | 0 | if ( pInputHandler ) |
1495 | 0 | pInputHandler->UpdateSpellSettings(); |
1496 | |
|
1497 | 0 | pViewSh->UpdateDrawTextOutliner(); |
1498 | 0 | } |
1499 | |
|
1500 | 0 | SetDocumentModified(); |
1501 | 0 | Broadcast(SfxHint(SfxHintId::LanguageChanged)); |
1502 | 0 | PostPaintGridAll(); |
1503 | 0 | } |
1504 | 0 | } |
1505 | 0 | } |
1506 | 0 | break; |
1507 | 0 | case SID_SPELLCHECK_IGNORE_ALL: |
1508 | 0 | { |
1509 | 0 | ScViewData* pViewData = GetViewData(); |
1510 | 0 | if (!pViewData) |
1511 | 0 | return; |
1512 | | |
1513 | 0 | EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart()); |
1514 | 0 | if (!pEditView) |
1515 | 0 | return; |
1516 | | |
1517 | 0 | OUString sIgnoreText; |
1518 | 0 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); |
1519 | 0 | if (pItem2) |
1520 | 0 | sIgnoreText = pItem2->GetValue(); |
1521 | |
|
1522 | 0 | if(sIgnoreText == "Spelling") |
1523 | 0 | { |
1524 | 0 | ESelection aOldSel = pEditView->GetSelection(); |
1525 | 0 | pEditView->SpellIgnoreWord(); |
1526 | 0 | pEditView->SetSelection( aOldSel ); |
1527 | 0 | } |
1528 | 0 | } |
1529 | 0 | break; |
1530 | 0 | case SID_SPELLCHECK_APPLY_SUGGESTION: |
1531 | 0 | { |
1532 | 0 | ScViewData* pViewData = GetViewData(); |
1533 | 0 | if (!pViewData) |
1534 | 0 | return; |
1535 | | |
1536 | 0 | EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart()); |
1537 | 0 | if (!pEditView) |
1538 | 0 | return; |
1539 | | |
1540 | 0 | OUString sApplyText; |
1541 | 0 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(FN_PARAM_1); |
1542 | 0 | if (pItem2) |
1543 | 0 | sApplyText = pItem2->GetValue(); |
1544 | |
|
1545 | 0 | static constexpr OUString sSpellingRule(u"Spelling_"_ustr); |
1546 | 0 | sal_Int32 nPos = 0; |
1547 | 0 | if(-1 != (nPos = sApplyText.indexOf( sSpellingRule ))) |
1548 | 0 | { |
1549 | 0 | sApplyText = sApplyText.replaceAt(nPos, sSpellingRule.getLength(), u""); |
1550 | 0 | pEditView->InsertText( sApplyText ); |
1551 | 0 | } |
1552 | 0 | } |
1553 | 0 | break; |
1554 | 0 | case SID_REFRESH_VIEW: |
1555 | 0 | { |
1556 | 0 | PostPaintGridAll(); |
1557 | 0 | } |
1558 | 0 | break; |
1559 | 0 | case SID_PROTECTPOS: |
1560 | 0 | case SID_PROTECTSIZE: |
1561 | 0 | { |
1562 | 0 | ScTabViewShell* pViewShell = GetBestViewShell(); |
1563 | 0 | if (!pViewShell) |
1564 | 0 | return; |
1565 | 0 | ScDrawView* pScDrawView = pViewShell->GetViewData().GetScDrawView(); |
1566 | 0 | if (!pScDrawView) |
1567 | 0 | return; |
1568 | | |
1569 | 0 | const SdrMarkList& rMarkList = pScDrawView->GetMarkedObjectList(); |
1570 | 0 | assert ( rMarkList.GetMarkCount() == 1 ); |
1571 | |
|
1572 | 0 | SdrObject* pGraphicObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); |
1573 | 0 | if (nSlot == SID_PROTECTSIZE) |
1574 | 0 | pGraphicObj->SetResizeProtect(!pGraphicObj->IsResizeProtect()); |
1575 | 0 | else |
1576 | 0 | pGraphicObj->SetMoveProtect(!pGraphicObj->IsMoveProtect()); |
1577 | 0 | } |
1578 | 0 | break; |
1579 | 0 | default: |
1580 | 0 | { |
1581 | | // small (?) hack -> forwarding of the slots to TabViewShell |
1582 | 0 | ScTabViewShell* pSh = GetBestViewShell(); |
1583 | 0 | if ( pSh ) |
1584 | 0 | pSh->Execute( rReq ); |
1585 | | #if HAVE_FEATURE_SCRIPTING |
1586 | | else |
1587 | | SbxBase::SetError( ERRCODE_BASIC_NO_ACTIVE_OBJECT ); |
1588 | | #endif |
1589 | 0 | } |
1590 | 0 | } |
1591 | 0 | } |
1592 | | |
1593 | | void UpdateAcceptChangesDialog() |
1594 | 0 | { |
1595 | | // update "accept changes" dialog |
1596 | | //! notify all views |
1597 | 0 | SfxViewFrame* pViewFrm = SfxViewFrame::Current(); |
1598 | 0 | if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) ) |
1599 | 0 | { |
1600 | 0 | SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT ); |
1601 | 0 | if ( pChild ) |
1602 | 0 | static_cast<ScAcceptChgDlgWrapper*>(pChild)->ReInitDlg(); |
1603 | 0 | } |
1604 | 0 | } |
1605 | | |
1606 | | void ScDocShell::ExecuteChartSource(SfxRequest& rReq) |
1607 | 0 | { |
1608 | 0 | const SfxItemSet* pReqArgs = rReq.GetArgs(); |
1609 | 0 | sal_uInt16 nSlot = rReq.GetSlot(); |
1610 | 0 | bool bUndo (m_pDocument->IsUndoEnabled()); |
1611 | 0 | if (!pReqArgs) |
1612 | 0 | { |
1613 | 0 | OSL_FAIL("SID_CHART_SOURCE without arguments"); |
1614 | 0 | return; |
1615 | 0 | } |
1616 | | |
1617 | 0 | ScDocument& rDoc = GetDocument(); |
1618 | 0 | const SfxPoolItem* pItem; |
1619 | 0 | OUString aChartName, aRangeName; |
1620 | |
|
1621 | 0 | ScRange aSingleRange; |
1622 | 0 | ScRangeListRef aRangeListRef; |
1623 | 0 | bool bMultiRange = false; |
1624 | |
|
1625 | 0 | bool bColHeaders = true; |
1626 | 0 | bool bRowHeaders = true; |
1627 | 0 | bool bColInit = false; |
1628 | 0 | bool bRowInit = false; |
1629 | 0 | bool bAddRange = (nSlot == SID_CHART_ADDSOURCE); |
1630 | |
|
1631 | 0 | if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_NAME ) ) |
1632 | 0 | aChartName = pChartItem->GetValue(); |
1633 | |
|
1634 | 0 | if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_SOURCE ) ) |
1635 | 0 | aRangeName = pChartItem->GetValue(); |
1636 | |
|
1637 | 0 | if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) |
1638 | 0 | { |
1639 | 0 | bColHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); |
1640 | 0 | bColInit = true; |
1641 | 0 | } |
1642 | 0 | if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) ) |
1643 | 0 | { |
1644 | 0 | bRowHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); |
1645 | 0 | bRowInit = true; |
1646 | 0 | } |
1647 | |
|
1648 | 0 | ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0); |
1649 | 0 | bool bValid = (aSingleRange.ParseAny(aRangeName, rDoc, aDetails) & ScRefFlags::VALID) != ScRefFlags::ZERO; |
1650 | 0 | if (!bValid) |
1651 | 0 | { |
1652 | 0 | aRangeListRef = new ScRangeList; |
1653 | 0 | aRangeListRef->Parse( aRangeName, rDoc, rDoc.GetAddressConvention()); |
1654 | 0 | if ( !aRangeListRef->empty() ) |
1655 | 0 | { |
1656 | 0 | bMultiRange = true; |
1657 | 0 | aSingleRange = aRangeListRef->front(); // for header |
1658 | 0 | bValid = true; |
1659 | 0 | } |
1660 | 0 | else |
1661 | 0 | aRangeListRef.clear(); |
1662 | 0 | } |
1663 | |
|
1664 | 0 | ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); |
1665 | 0 | if (!pViewSh || !bValid || aChartName.isEmpty() ) |
1666 | 0 | { |
1667 | 0 | OSL_FAIL("UpdateChartArea: no ViewShell or wrong data"); |
1668 | 0 | rReq.Done(); |
1669 | 0 | return; |
1670 | 0 | } |
1671 | | |
1672 | 0 | weld::Window* pParent = pViewSh->GetFrameWeld(); |
1673 | |
|
1674 | 0 | SCCOL nCol1 = aSingleRange.aStart.Col(); |
1675 | 0 | SCROW nRow1 = aSingleRange.aStart.Row(); |
1676 | 0 | SCCOL nCol2 = aSingleRange.aEnd.Col(); |
1677 | 0 | SCROW nRow2 = aSingleRange.aEnd.Row(); |
1678 | 0 | SCTAB nTab = aSingleRange.aStart.Tab(); |
1679 | | |
1680 | | //! limit always or not at all ??? |
1681 | 0 | if (!bMultiRange) |
1682 | 0 | m_pDocument->LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 ); |
1683 | | |
1684 | | // Dialog for column/row headers |
1685 | 0 | if ( !bAddRange && ( !bColInit || !bRowInit ) ) |
1686 | 0 | { |
1687 | 0 | ScChartPositioner aChartPositioner( *m_pDocument, nTab, nCol1,nRow1, nCol2,nRow2 ); |
1688 | 0 | if (!bColInit) |
1689 | 0 | bColHeaders = aChartPositioner.HasColHeaders(); |
1690 | 0 | if (!bRowInit) |
1691 | 0 | bRowHeaders = aChartPositioner.HasRowHeaders(); |
1692 | |
|
1693 | 0 | auto xRequest = std::make_shared<SfxRequest>(rReq); |
1694 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
1695 | 0 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); |
1696 | 0 | VclPtr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders)); |
1697 | 0 | pDlg->StartExecuteAsync( |
1698 | 0 | [this, pDlg, xRequest=std::move(xRequest), bUndo, bMultiRange, |
1699 | 0 | aChartName, aRangeListRef=std::move(aRangeListRef), bAddRange, |
1700 | 0 | nCol1, nRow1, nCol2, nRow2, nTab] (sal_Int32 nResult)->void |
1701 | 0 | { |
1702 | 0 | if (nResult == RET_OK) |
1703 | 0 | { |
1704 | 0 | bool bColHeaders2 = pDlg->IsRow(); |
1705 | 0 | bool bRowHeaders2 = pDlg->IsCol(); |
1706 | |
|
1707 | 0 | xRequest->AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders2)); |
1708 | 0 | xRequest->AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders2)); |
1709 | 0 | ExecuteChartSourcePost(bUndo, bMultiRange, |
1710 | 0 | aChartName, aRangeListRef, bColHeaders2, bRowHeaders2, bAddRange, |
1711 | 0 | nCol1, nRow1, nCol2, nRow2, nTab); |
1712 | 0 | } |
1713 | 0 | pDlg->disposeOnce(); |
1714 | 0 | xRequest->Done(); |
1715 | 0 | } |
1716 | 0 | ); |
1717 | 0 | } |
1718 | 0 | else |
1719 | 0 | { |
1720 | 0 | ExecuteChartSourcePost(bUndo, bMultiRange, |
1721 | 0 | aChartName, aRangeListRef, bColHeaders, bRowHeaders, bAddRange, |
1722 | 0 | nCol1, nRow1,nCol2, nRow2, nTab); |
1723 | 0 | rReq.Done(); |
1724 | 0 | } |
1725 | 0 | } |
1726 | | |
1727 | | void ScDocShell::ExecuteChartSourcePost(bool bUndo, bool bMultiRange, |
1728 | | const OUString& rChartName, const ScRangeListRef& rRangeListRef, |
1729 | | bool bColHeaders, bool bRowHeaders, bool bAddRange, |
1730 | | SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab ) |
1731 | 0 | { |
1732 | 0 | if (bMultiRange) |
1733 | 0 | { |
1734 | 0 | if (bUndo) |
1735 | 0 | { |
1736 | 0 | GetUndoManager()->AddUndoAction( |
1737 | 0 | std::make_unique<ScUndoChartData>( *this, rChartName, rRangeListRef, |
1738 | 0 | bColHeaders, bRowHeaders, bAddRange ) ); |
1739 | 0 | } |
1740 | 0 | m_pDocument->UpdateChartArea( rChartName, rRangeListRef, |
1741 | 0 | bColHeaders, bRowHeaders, bAddRange ); |
1742 | 0 | } |
1743 | 0 | else |
1744 | 0 | { |
1745 | 0 | ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); |
1746 | 0 | if (bUndo) |
1747 | 0 | { |
1748 | 0 | GetUndoManager()->AddUndoAction( |
1749 | 0 | std::make_unique<ScUndoChartData>( *this, rChartName, aNewRange, |
1750 | 0 | bColHeaders, bRowHeaders, bAddRange ) ); |
1751 | 0 | } |
1752 | 0 | m_pDocument->UpdateChartArea( rChartName, aNewRange, |
1753 | 0 | bColHeaders, bRowHeaders, bAddRange ); |
1754 | 0 | } |
1755 | 0 | } |
1756 | | |
1757 | | bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected ) |
1758 | 0 | { |
1759 | 0 | bool bDone = false; |
1760 | 0 | ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack(); |
1761 | 0 | if ( pChangeTrack ) |
1762 | 0 | { |
1763 | 0 | bool bProtected = pChangeTrack->IsProtected(); |
1764 | 0 | if ( bJustQueryIfProtected && !bProtected ) |
1765 | 0 | return true; |
1766 | | |
1767 | 0 | OUString aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) ); |
1768 | 0 | OUString aText( ScResId( SCSTR_PASSWORD ) ); |
1769 | 0 | OUString aPassword; |
1770 | |
|
1771 | 0 | weld::Window* pWin = ScDocShell::GetActiveDialogParent(); |
1772 | 0 | SfxPasswordDialog aDlg(pWin, &aText); |
1773 | 0 | aDlg.set_title(aTitle); |
1774 | 0 | aDlg.SetMinLen(1); |
1775 | 0 | aDlg.set_help_id(GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand()); |
1776 | 0 | aDlg.SetEditHelpId( HID_CHG_PROTECT ); |
1777 | 0 | if ( !bProtected ) |
1778 | 0 | aDlg.ShowExtras(SfxShowExtras::CONFIRM); |
1779 | 0 | if (aDlg.run() == RET_OK) |
1780 | 0 | aPassword = aDlg.GetPassword(); |
1781 | |
|
1782 | 0 | if (!aPassword.isEmpty()) |
1783 | 0 | { |
1784 | 0 | if ( bProtected ) |
1785 | 0 | { |
1786 | 0 | if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) ) |
1787 | 0 | { |
1788 | 0 | if ( bJustQueryIfProtected ) |
1789 | 0 | bDone = true; |
1790 | 0 | else |
1791 | 0 | pChangeTrack->SetProtection( {} ); |
1792 | 0 | } |
1793 | 0 | else |
1794 | 0 | { |
1795 | 0 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin, |
1796 | 0 | VclMessageType::Info, VclButtonsType::Ok, |
1797 | 0 | ScResId(SCSTR_WRONGPASSWORD))); |
1798 | 0 | xInfoBox->run(); |
1799 | 0 | } |
1800 | 0 | } |
1801 | 0 | else |
1802 | 0 | { |
1803 | 0 | css::uno::Sequence< sal_Int8 > aPass; |
1804 | 0 | SvPasswordHelper::GetHashPassword( aPass, aPassword ); |
1805 | 0 | pChangeTrack->SetProtection( aPass ); |
1806 | 0 | } |
1807 | 0 | if ( bProtected != pChangeTrack->IsProtected() ) |
1808 | 0 | { |
1809 | 0 | UpdateAcceptChangesDialog(); |
1810 | 0 | bDone = true; |
1811 | 0 | } |
1812 | 0 | } |
1813 | 0 | } |
1814 | 0 | else if ( bJustQueryIfProtected ) |
1815 | 0 | bDone = true; |
1816 | 0 | return bDone; |
1817 | 0 | } |
1818 | | |
1819 | | void ScDocShell::DoRecalc( bool bApi ) |
1820 | 0 | { |
1821 | 0 | if (m_pDocument->IsInDocShellRecalc()) |
1822 | 0 | { |
1823 | 0 | SAL_WARN("sc","ScDocShell::DoRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher."); |
1824 | 0 | return; |
1825 | 0 | } |
1826 | 0 | ScDocShellRecalcGuard aGuard(*m_pDocument); |
1827 | 0 | bool bDone = false; |
1828 | 0 | ScTabViewShell* pSh = GetBestViewShell(); |
1829 | 0 | ScInputHandler* pHdl = (pSh ? ScModule::get()->GetInputHdl(pSh) : nullptr); |
1830 | 0 | if ( pSh ) |
1831 | 0 | { |
1832 | 0 | if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi ) |
1833 | 0 | { |
1834 | 0 | pHdl->FormulaPreview(); // partial result as QuickHelp |
1835 | 0 | bDone = true; |
1836 | 0 | } |
1837 | 0 | else |
1838 | 0 | { |
1839 | 0 | ScTabView::UpdateInputLine(); // InputEnterHandler |
1840 | 0 | pSh->UpdateInputHandler(); |
1841 | 0 | } |
1842 | 0 | } |
1843 | 0 | if (bDone) // otherwise re-calculate document |
1844 | 0 | return; |
1845 | | |
1846 | 0 | weld::WaitObject aWaitObj( GetActiveDialogParent() ); |
1847 | 0 | if ( pHdl ) |
1848 | 0 | { |
1849 | | // tdf97897 set current cell to Dirty to force recalculation of cell |
1850 | 0 | ScFormulaCell* pFC = m_pDocument->GetFormulaCell( pHdl->GetCursorPos()); |
1851 | 0 | if (pFC) |
1852 | 0 | pFC->SetDirty(); |
1853 | 0 | } |
1854 | 0 | m_pDocument->CalcFormulaTree(); |
1855 | 0 | if ( pSh ) |
1856 | 0 | pSh->UpdateCharts(true); |
1857 | |
|
1858 | 0 | m_pDocument->BroadcastUno( SfxHint( SfxHintId::DataChanged ) ); |
1859 | | |
1860 | | // If there are charts, then paint everything, so that PostDataChanged |
1861 | | // and the charts do not come one after the other and parts are painted twice. |
1862 | |
|
1863 | 0 | ScChartListenerCollection* pCharts = m_pDocument->GetChartListenerCollection(); |
1864 | 0 | if ( pCharts && pCharts->hasListeners() ) |
1865 | 0 | PostPaintGridAll(); |
1866 | 0 | else |
1867 | 0 | PostDataChanged(); |
1868 | 0 | } |
1869 | | |
1870 | | void ScDocShell::DoHardRecalc() |
1871 | 7.78k | { |
1872 | 7.78k | if (m_pDocument->IsInDocShellRecalc()) |
1873 | 0 | { |
1874 | 0 | SAL_WARN("sc","ScDocShell::DoHardRecalc tries re-entering while in Recalc; probably Forms->BASIC->Dispatcher."); |
1875 | 0 | return; |
1876 | 0 | } |
1877 | 7.78k | auto start = std::chrono::steady_clock::now(); |
1878 | 7.78k | ScDocShellRecalcGuard aGuard(*m_pDocument); |
1879 | 7.78k | weld::WaitObject aWaitObj( GetActiveDialogParent() ); |
1880 | 7.78k | ScTabViewShell* pSh = GetBestViewShell(); |
1881 | 7.78k | if ( pSh ) |
1882 | 0 | { |
1883 | 0 | ScTabView::UpdateInputLine(); // InputEnterHandler |
1884 | 0 | pSh->UpdateInputHandler(); |
1885 | 0 | } |
1886 | 7.78k | m_pDocument->CalcAll(); |
1887 | 7.78k | GetDocFunc().DetectiveRefresh(); // creates own Undo |
1888 | 7.78k | if ( pSh ) |
1889 | 0 | pSh->UpdateCharts(true); |
1890 | | |
1891 | | // set notification flags for "calculate" event (used in SfxHintId::DataChanged broadcast) |
1892 | | // (might check for the presence of any formulas on each sheet) |
1893 | 7.78k | SCTAB nTabCount = m_pDocument->GetTableCount(); |
1894 | 7.78k | if (m_pDocument->HasAnySheetEventScript( ScSheetEventId::CALCULATE, true )) // search also for VBA handler |
1895 | 0 | for (SCTAB nTab=0; nTab<nTabCount; nTab++) |
1896 | 0 | m_pDocument->SetCalcNotification(nTab); |
1897 | | |
1898 | | // CalcAll doesn't broadcast value changes, so SfxHintId::ScCalcAll is broadcasted globally |
1899 | | // in addition to SfxHintId::DataChanged. |
1900 | 7.78k | m_pDocument->BroadcastUno( SfxHint( SfxHintId::ScCalcAll ) ); |
1901 | 7.78k | m_pDocument->BroadcastUno( SfxHint( SfxHintId::DataChanged ) ); |
1902 | | |
1903 | | // use hard recalc also to disable stream-copying of all sheets |
1904 | | // (somewhat consistent with charts) |
1905 | 25.7k | for (SCTAB nTab=0; nTab<nTabCount; nTab++) |
1906 | 17.9k | m_pDocument->SetStreamValid(nTab, false); |
1907 | | |
1908 | 7.78k | PostPaintGridAll(); |
1909 | 7.78k | auto end = std::chrono::steady_clock::now(); |
1910 | 7.78k | SAL_INFO("sc.timing", "ScDocShell::DoHardRecalc(): took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms"); |
1911 | 7.78k | } |
1912 | | |
1913 | | void ScDocShell::DoAutoStyle( const ScRange& rRange, const OUString& rStyle ) |
1914 | 0 | { |
1915 | 0 | ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool(); |
1916 | 0 | ScStyleSheet* pStyleSheet = pStylePool->FindAutoStyle(rStyle); |
1917 | 0 | if (!pStyleSheet) |
1918 | 0 | return; |
1919 | | |
1920 | 0 | OSL_ENSURE(rRange.aStart.Tab() == rRange.aEnd.Tab(), |
1921 | 0 | "DoAutoStyle with several tables"); |
1922 | 0 | SCTAB nTab = rRange.aStart.Tab(); |
1923 | 0 | SCCOL nStartCol = rRange.aStart.Col(); |
1924 | 0 | SCROW nStartRow = rRange.aStart.Row(); |
1925 | 0 | SCCOL nEndCol = rRange.aEnd.Col(); |
1926 | 0 | SCROW nEndRow = rRange.aEnd.Row(); |
1927 | 0 | m_pDocument->ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet ); |
1928 | 0 | m_pDocument->ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab ); |
1929 | 0 | PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid ); |
1930 | 0 | } |
1931 | | |
1932 | | void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint ) |
1933 | 32.5k | { |
1934 | 32.5k | SfxHintId nId = rHint.GetId(); |
1935 | 32.5k | const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet(); |
1936 | 32.5k | if (!pStyle) |
1937 | 0 | return; |
1938 | | |
1939 | 32.5k | if ( pStyle->GetFamily() == SfxStyleFamily::Page ) |
1940 | 0 | { |
1941 | 0 | if ( nId == SfxHintId::StyleSheetModified || nId == SfxHintId::StyleSheetModifiedExtended ) |
1942 | 0 | { |
1943 | 0 | ScDocShellModificator aModificator( *this ); |
1944 | |
|
1945 | 0 | const OUString& aNewName = pStyle->GetName(); |
1946 | 0 | OUString aOldName = aNewName; |
1947 | 0 | if ( nId == SfxHintId::StyleSheetModifiedExtended ) |
1948 | 0 | { |
1949 | 0 | const SfxStyleSheetModifiedHint& rExtendedHint = static_cast<const SfxStyleSheetModifiedHint&>(rHint); // name changed? |
1950 | 0 | aOldName = rExtendedHint.GetOldName(); |
1951 | 0 | } |
1952 | 0 | if ( aNewName != aOldName ) |
1953 | 0 | m_pDocument->RenamePageStyleInUse( aOldName, aNewName ); |
1954 | |
|
1955 | 0 | SCTAB nTabCount = m_pDocument->GetTableCount(); |
1956 | 0 | for (SCTAB nTab=0; nTab<nTabCount; nTab++) |
1957 | 0 | if (m_pDocument->GetPageStyle(nTab) == aNewName) // already adjusted to new |
1958 | 0 | { |
1959 | 0 | m_pDocument->PageStyleModified( nTab, aNewName ); |
1960 | 0 | ScPrintFunc aPrintFunc( *this, GetPrinter(), nTab ); |
1961 | 0 | aPrintFunc.UpdatePages(); |
1962 | 0 | } |
1963 | |
|
1964 | 0 | aModificator.SetDocumentModified(); |
1965 | |
|
1966 | 0 | if (nId == SfxHintId::StyleSheetModifiedExtended) |
1967 | 0 | { |
1968 | 0 | SfxBindings* pBindings = GetViewBindings(); |
1969 | 0 | if (pBindings) |
1970 | 0 | { |
1971 | 0 | pBindings->Invalidate( SID_STATUS_PAGESTYLE ); |
1972 | 0 | pBindings->Invalidate( SID_STYLE_FAMILY4 ); |
1973 | 0 | pBindings->Invalidate( FID_RESET_PRINTZOOM ); |
1974 | 0 | pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT ); |
1975 | 0 | pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT ); |
1976 | 0 | } |
1977 | 0 | } |
1978 | 0 | } |
1979 | 0 | } |
1980 | 32.5k | else if ( pStyle->GetFamily() == SfxStyleFamily::Para ) |
1981 | 14.7k | { |
1982 | 14.7k | if (nId == SfxHintId::StyleSheetModifiedExtended) |
1983 | 0 | { |
1984 | 0 | const SfxStyleSheetModifiedHint& rExtendedHint = static_cast<const SfxStyleSheetModifiedHint&>(rHint); |
1985 | 0 | const OUString& aNewName = pStyle->GetName(); |
1986 | 0 | const OUString& aOldName = rExtendedHint.GetOldName(); |
1987 | 0 | if ( aNewName != aOldName ) |
1988 | 0 | { |
1989 | 0 | for(SCTAB i = 0; i < m_pDocument->GetTableCount(); ++i) |
1990 | 0 | { |
1991 | 0 | ScConditionalFormatList* pList = m_pDocument->GetCondFormList(i); |
1992 | 0 | if (pList) |
1993 | 0 | pList->RenameCellStyle( aOldName,aNewName ); |
1994 | 0 | } |
1995 | 0 | } |
1996 | 0 | } |
1997 | 14.7k | } |
1998 | | |
1999 | | // everything else goes via slots... |
2000 | 32.5k | } |
2001 | | |
2002 | | // like in printfun.cxx |
2003 | 0 | #define ZOOM_MIN 10 |
2004 | | |
2005 | | void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages ) |
2006 | 0 | { |
2007 | 0 | OUString aStyleName = m_pDocument->GetPageStyle( nTab ); |
2008 | 0 | ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool(); |
2009 | 0 | SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page ); |
2010 | 0 | OSL_ENSURE( pStyleSheet, "PageStyle not found" ); |
2011 | 0 | if ( !pStyleSheet ) |
2012 | 0 | return; |
2013 | | |
2014 | 0 | ScDocShellModificator aModificator( *this ); |
2015 | |
|
2016 | 0 | SfxItemSet& rSet = pStyleSheet->GetItemSet(); |
2017 | 0 | const bool bUndo(m_pDocument->IsUndoEnabled()); |
2018 | 0 | if (bUndo) |
2019 | 0 | { |
2020 | 0 | sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue(); |
2021 | 0 | sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue(); |
2022 | 0 | GetUndoManager()->AddUndoAction( std::make_unique<ScUndoPrintZoom>( |
2023 | 0 | *this, nTab, nOldScale, nOldPages, nScale, nPages ) ); |
2024 | 0 | } |
2025 | |
|
2026 | 0 | rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) ); |
2027 | 0 | rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) ); |
2028 | |
|
2029 | 0 | ScPrintFunc aPrintFunc( *this, GetPrinter(), nTab ); |
2030 | 0 | aPrintFunc.UpdatePages(); |
2031 | 0 | aModificator.SetDocumentModified(); |
2032 | |
|
2033 | 0 | SfxBindings* pBindings = GetViewBindings(); |
2034 | 0 | if (pBindings) |
2035 | 0 | pBindings->Invalidate( FID_RESET_PRINTZOOM ); |
2036 | 0 | } |
2037 | | |
2038 | | bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) |
2039 | 0 | { |
2040 | 0 | bool bChange = false; |
2041 | 0 | SCTAB nTab = rRange.aStart.Tab(); |
2042 | |
|
2043 | 0 | OUString aStyleName = m_pDocument->GetPageStyle( nTab ); |
2044 | 0 | ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool(); |
2045 | 0 | SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page ); |
2046 | 0 | OSL_ENSURE( pStyleSheet, "PageStyle not found" ); |
2047 | 0 | if ( pStyleSheet ) |
2048 | 0 | { |
2049 | 0 | SfxItemSet& rSet = pStyleSheet->GetItemSet(); |
2050 | 0 | bool bHeaders = rSet.Get(ATTR_PAGE_HEADERS).GetValue(); |
2051 | 0 | sal_uInt16 nOldScale = rSet.Get(ATTR_PAGE_SCALE).GetValue(); |
2052 | 0 | sal_uInt16 nOldPages = rSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue(); |
2053 | 0 | std::optional<ScRange> oRepeatCol = m_pDocument->GetRepeatColRange( nTab ); |
2054 | 0 | std::optional<ScRange> oRepeatRow = m_pDocument->GetRepeatRowRange( nTab ); |
2055 | | |
2056 | | // calculate needed scaling for selection |
2057 | |
|
2058 | 0 | sal_uInt16 nNewScale = nOldScale; |
2059 | |
|
2060 | 0 | tools::Long nBlkTwipsX = 0; |
2061 | 0 | if (bHeaders) |
2062 | 0 | nBlkTwipsX += PRINT_HEADER_WIDTH; |
2063 | 0 | SCCOL nStartCol = rRange.aStart.Col(); |
2064 | 0 | SCCOL nEndCol = rRange.aEnd.Col(); |
2065 | 0 | if ( oRepeatCol && nStartCol >= oRepeatCol->aStart.Col() ) |
2066 | 0 | { |
2067 | 0 | for (SCCOL i=oRepeatCol->aStart.Col(); i<=oRepeatCol->aEnd.Col(); i++ ) |
2068 | 0 | nBlkTwipsX += m_pDocument->GetColWidth( i, nTab ); |
2069 | 0 | if ( nStartCol <= oRepeatCol->aEnd.Col() ) |
2070 | 0 | nStartCol = oRepeatCol->aEnd.Col() + 1; |
2071 | 0 | } |
2072 | | // legacy compilers' own scope for i |
2073 | 0 | { |
2074 | 0 | for ( SCCOL i=nStartCol; i<=nEndCol; i++ ) |
2075 | 0 | nBlkTwipsX += m_pDocument->GetColWidth( i, nTab ); |
2076 | 0 | } |
2077 | |
|
2078 | 0 | tools::Long nBlkTwipsY = 0; |
2079 | 0 | if (bHeaders) |
2080 | 0 | nBlkTwipsY += PRINT_HEADER_HEIGHT; |
2081 | 0 | SCROW nStartRow = rRange.aStart.Row(); |
2082 | 0 | SCROW nEndRow = rRange.aEnd.Row(); |
2083 | 0 | if ( oRepeatRow && nStartRow >= oRepeatRow->aStart.Row() ) |
2084 | 0 | { |
2085 | 0 | nBlkTwipsY += m_pDocument->GetRowHeight( oRepeatRow->aStart.Row(), |
2086 | 0 | oRepeatRow->aEnd.Row(), nTab ); |
2087 | 0 | if ( nStartRow <= oRepeatRow->aEnd.Row() ) |
2088 | 0 | nStartRow = oRepeatRow->aEnd.Row() + 1; |
2089 | 0 | } |
2090 | 0 | nBlkTwipsY += m_pDocument->GetRowHeight( nStartRow, nEndRow, nTab ); |
2091 | |
|
2092 | 0 | Size aPhysPage; |
2093 | 0 | tools::Long nHdr, nFtr; |
2094 | 0 | ScPrintFunc aOldPrFunc( *this, GetPrinter(), nTab ); |
2095 | 0 | aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr ); |
2096 | 0 | nBlkTwipsY += nHdr + nFtr; |
2097 | |
|
2098 | 0 | if ( nBlkTwipsX == 0 ) // hidden columns/rows may lead to 0 |
2099 | 0 | nBlkTwipsX = 1; |
2100 | 0 | if ( nBlkTwipsY == 0 ) |
2101 | 0 | nBlkTwipsY = 1; |
2102 | |
|
2103 | 0 | tools::Long nNeeded = std::min( aPhysPage.Width() * 100 / nBlkTwipsX, |
2104 | 0 | aPhysPage.Height() * 100 / nBlkTwipsY ); |
2105 | 0 | if ( nNeeded < ZOOM_MIN ) |
2106 | 0 | nNeeded = ZOOM_MIN; // boundary |
2107 | 0 | if ( nNeeded < static_cast<tools::Long>(nNewScale) ) |
2108 | 0 | nNewScale = static_cast<sal_uInt16>(nNeeded); |
2109 | |
|
2110 | 0 | bChange = ( nNewScale != nOldScale || nOldPages != 0 ); |
2111 | 0 | if ( bChange ) |
2112 | 0 | SetPrintZoom( nTab, nNewScale, 0 ); |
2113 | 0 | } |
2114 | 0 | return bChange; |
2115 | 0 | } |
2116 | | |
2117 | | void ScDocShell::PageStyleModified( std::u16string_view rStyleName, bool bApi ) |
2118 | 166k | { |
2119 | 166k | ScDocShellModificator aModificator( *this ); |
2120 | | |
2121 | 166k | SCTAB nTabCount = m_pDocument->GetTableCount(); |
2122 | 166k | SCTAB nUseTab = MAXTAB+1; |
2123 | 730k | for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++) |
2124 | 564k | if ( m_pDocument->GetPageStyle(nTab) == rStyleName && |
2125 | 3.38k | ( !bApi || m_pDocument->GetPageSize(nTab).Width() ) ) |
2126 | 128 | nUseTab = nTab; |
2127 | | // at bApi only if breaks already shown |
2128 | | |
2129 | 166k | if (ValidTab(nUseTab)) // not used -> nothing to do |
2130 | 128 | { |
2131 | 128 | bool bWarn = false; |
2132 | | |
2133 | 128 | ScPrintFunc aPrintFunc( *this, GetPrinter(), nUseTab ); //! cope without CountPages |
2134 | 128 | if (!aPrintFunc.UpdatePages()) // sets breaks on all tabs |
2135 | 0 | bWarn = true; |
2136 | | |
2137 | 128 | if (bWarn && !bApi) |
2138 | 0 | { |
2139 | 0 | weld::Window* pWin = GetActiveDialogParent(); |
2140 | 0 | weld::WaitObject aWaitOff(pWin); |
2141 | 0 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin, |
2142 | 0 | VclMessageType::Info, VclButtonsType::Ok, |
2143 | 0 | ScResId(STR_PRINT_INVALID_AREA))); |
2144 | 0 | xInfoBox->run(); |
2145 | 0 | } |
2146 | 128 | } |
2147 | | |
2148 | 166k | aModificator.SetDocumentModified(); |
2149 | | |
2150 | 166k | SfxBindings* pBindings = GetViewBindings(); |
2151 | 166k | if (pBindings) |
2152 | 0 | { |
2153 | 0 | pBindings->Invalidate( FID_RESET_PRINTZOOM ); |
2154 | 0 | pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT ); |
2155 | 0 | pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT ); |
2156 | 0 | } |
2157 | 166k | } |
2158 | | |
2159 | | void ScDocShell::ExecutePageStyle( const SfxViewShell& rCaller, |
2160 | | SfxRequest& rReq, |
2161 | | SCTAB nCurTab ) |
2162 | 0 | { |
2163 | 0 | const SfxItemSet* pReqArgs = rReq.GetArgs(); |
2164 | |
|
2165 | 0 | switch ( rReq.GetSlot() ) |
2166 | 0 | { |
2167 | 0 | case SID_STATUS_PAGESTYLE: // click on StatusBar control |
2168 | 0 | case SID_FORMATPAGE: |
2169 | 0 | { |
2170 | 0 | if ( pReqArgs == nullptr ) |
2171 | 0 | { |
2172 | 0 | OUString aOldName = m_pDocument->GetPageStyle( nCurTab ); |
2173 | 0 | ScStyleSheetPool* pStylePool = m_pDocument->GetStyleSheetPool(); |
2174 | 0 | SfxStyleSheetBase* pStyleSheet |
2175 | 0 | = pStylePool->Find( aOldName, SfxStyleFamily::Page ); |
2176 | |
|
2177 | 0 | OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" ); |
2178 | |
|
2179 | 0 | if ( pStyleSheet ) |
2180 | 0 | { |
2181 | 0 | auto xOldData = std::make_shared<ScStyleSaveData>(); |
2182 | 0 | const bool bUndo(m_pDocument->IsUndoEnabled()); |
2183 | 0 | if (bUndo) |
2184 | 0 | xOldData->InitFromStyle(pStyleSheet); |
2185 | |
|
2186 | 0 | SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); |
2187 | 0 | rStyleSet.MergeRange( XATTR_FILL_FIRST, XATTR_FILL_LAST ); |
2188 | |
|
2189 | 0 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); |
2190 | |
|
2191 | 0 | VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScStyleDlg(GetActiveDialogParent(), *pStyleSheet, true)); |
2192 | |
|
2193 | 0 | auto xRequest = std::make_shared<SfxRequest>(rReq); |
2194 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
2195 | 0 | pDlg->StartExecuteAsync([this, pDlg, xRequest=std::move(xRequest), pStyleSheet, |
2196 | 0 | xOldData=std::move(xOldData), aOldName, |
2197 | 0 | &rCaller, bUndo](sal_Int32 nResult) { |
2198 | 0 | if ( nResult == RET_OK ) |
2199 | 0 | { |
2200 | 0 | const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); |
2201 | |
|
2202 | 0 | weld::WaitObject aWait( GetActiveDialogParent() ); |
2203 | |
|
2204 | 0 | OUString aNewName = pStyleSheet->GetName(); |
2205 | 0 | if ( aNewName != aOldName && |
2206 | 0 | m_pDocument->RenamePageStyleInUse( aOldName, aNewName ) ) |
2207 | 0 | { |
2208 | 0 | SfxBindings* pBindings = GetViewBindings(); |
2209 | 0 | if (pBindings) |
2210 | 0 | { |
2211 | 0 | pBindings->Invalidate( SID_STATUS_PAGESTYLE ); |
2212 | 0 | pBindings->Invalidate( FID_RESET_PRINTZOOM ); |
2213 | 0 | } |
2214 | 0 | } |
2215 | |
|
2216 | 0 | if ( pOutSet ) |
2217 | 0 | m_pDocument->ModifyStyleSheet( *pStyleSheet, *pOutSet ); |
2218 | |
|
2219 | 0 | rCaller.GetViewFrame().GetBindings().Invalidate( SID_HFEDIT ); |
2220 | |
|
2221 | 0 | ScStyleSaveData aNewData; |
2222 | 0 | aNewData.InitFromStyle( pStyleSheet ); |
2223 | 0 | if (bUndo) |
2224 | 0 | { |
2225 | 0 | GetUndoManager()->AddUndoAction( |
2226 | 0 | std::make_unique<ScUndoModifyStyle>( *this, SfxStyleFamily::Page, |
2227 | 0 | *xOldData, aNewData ) ); |
2228 | 0 | } |
2229 | |
|
2230 | 0 | PageStyleModified( aNewName, false ); |
2231 | 0 | xRequest->Done(); |
2232 | 0 | } |
2233 | 0 | pDlg->disposeOnce(); |
2234 | 0 | }); |
2235 | 0 | } |
2236 | 0 | } |
2237 | 0 | } |
2238 | 0 | break; |
2239 | | |
2240 | 0 | case SID_HFEDIT: |
2241 | 0 | { |
2242 | 0 | if ( pReqArgs == nullptr ) |
2243 | 0 | { |
2244 | 0 | OUString aStr( m_pDocument->GetPageStyle( nCurTab ) ); |
2245 | |
|
2246 | 0 | ScStyleSheetPool* pStylePool |
2247 | 0 | = m_pDocument->GetStyleSheetPool(); |
2248 | |
|
2249 | 0 | SfxStyleSheetBase* pStyleSheet |
2250 | 0 | = pStylePool->Find( aStr, SfxStyleFamily::Page ); |
2251 | |
|
2252 | 0 | OSL_ENSURE( pStyleSheet, "PageStyle not found! :-/" ); |
2253 | |
|
2254 | 0 | if ( pStyleSheet ) |
2255 | 0 | { |
2256 | 0 | SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); |
2257 | |
|
2258 | 0 | SvxPageUsage eUsage = rStyleSet.Get( ATTR_PAGE ).GetPageUsage(); |
2259 | 0 | bool bShareHeader = rStyleSet |
2260 | 0 | .Get(ATTR_PAGE_HEADERSET) |
2261 | 0 | .GetItemSet() |
2262 | 0 | .Get(ATTR_PAGE_SHARED) |
2263 | 0 | .GetValue(); |
2264 | 0 | bool bShareFooter = rStyleSet |
2265 | 0 | .Get(ATTR_PAGE_FOOTERSET) |
2266 | 0 | .GetItemSet() |
2267 | 0 | .Get(ATTR_PAGE_SHARED) |
2268 | 0 | .GetValue(); |
2269 | 0 | sal_uInt16 nResId = 0; |
2270 | |
|
2271 | 0 | switch ( eUsage ) |
2272 | 0 | { |
2273 | 0 | case SvxPageUsage::Left: |
2274 | 0 | case SvxPageUsage::Right: |
2275 | 0 | nResId = RID_SCDLG_HFEDIT; |
2276 | 0 | break; |
2277 | | |
2278 | 0 | case SvxPageUsage::Mirror: |
2279 | 0 | case SvxPageUsage::All: |
2280 | 0 | default: |
2281 | 0 | { |
2282 | 0 | if ( !bShareHeader && !bShareFooter ) |
2283 | 0 | nResId = RID_SCDLG_HFEDIT_ALL; |
2284 | 0 | else if ( bShareHeader && bShareFooter ) |
2285 | 0 | nResId = RID_SCDLG_HFEDIT; |
2286 | 0 | else if ( !bShareHeader && bShareFooter ) |
2287 | 0 | nResId = RID_SCDLG_HFEDIT_SFTR; |
2288 | 0 | else if ( bShareHeader && !bShareFooter ) |
2289 | 0 | nResId = RID_SCDLG_HFEDIT_SHDR; |
2290 | 0 | } |
2291 | 0 | break; |
2292 | 0 | } |
2293 | | |
2294 | 0 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); |
2295 | |
|
2296 | 0 | VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScHFEditDlg( |
2297 | 0 | GetActiveDialogParent(), |
2298 | 0 | rStyleSet, |
2299 | 0 | aStr, |
2300 | 0 | nResId)); |
2301 | 0 | auto xRequest = std::make_shared<SfxRequest>(rReq); |
2302 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
2303 | 0 | pDlg->StartExecuteAsync([this, pDlg, pStyleSheet, xRequest=std::move(xRequest)](sal_Int32 nResult){ |
2304 | 0 | if ( nResult == RET_OK ) |
2305 | 0 | { |
2306 | 0 | const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); |
2307 | |
|
2308 | 0 | if ( pOutSet ) |
2309 | 0 | m_pDocument->ModifyStyleSheet( *pStyleSheet, *pOutSet ); |
2310 | |
|
2311 | 0 | SetDocumentModified(); |
2312 | 0 | xRequest->Done(); |
2313 | 0 | } |
2314 | 0 | pDlg->disposeOnce(); |
2315 | 0 | }); |
2316 | 0 | } |
2317 | 0 | } |
2318 | 0 | } |
2319 | 0 | break; |
2320 | | |
2321 | 0 | default: |
2322 | 0 | break; |
2323 | 0 | } |
2324 | 0 | } |
2325 | | |
2326 | | void ScDocShell::GetStatePageStyle( SfxItemSet& rSet, |
2327 | | SCTAB nCurTab ) |
2328 | 0 | { |
2329 | 0 | SfxWhichIter aIter(rSet); |
2330 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
2331 | 0 | while ( nWhich ) |
2332 | 0 | { |
2333 | 0 | switch (nWhich) |
2334 | 0 | { |
2335 | 0 | case SID_STATUS_PAGESTYLE: |
2336 | 0 | rSet.Put( SfxStringItem( nWhich, m_pDocument->GetPageStyle( nCurTab ) ) ); |
2337 | 0 | break; |
2338 | 0 | } |
2339 | | |
2340 | 0 | nWhich = aIter.NextWhich(); |
2341 | 0 | } |
2342 | 0 | } |
2343 | | |
2344 | | void ScDocShell::GetState( SfxItemSet &rSet ) |
2345 | 0 | { |
2346 | 0 | bool bTabView = GetBestViewShell() != nullptr; |
2347 | |
|
2348 | 0 | SfxWhichIter aIter(rSet); |
2349 | 0 | for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich()) |
2350 | 0 | { |
2351 | 0 | if (!bTabView) |
2352 | 0 | { |
2353 | 0 | rSet.DisableItem(nWhich); |
2354 | 0 | continue; |
2355 | 0 | } |
2356 | | |
2357 | 0 | switch (nWhich) |
2358 | 0 | { |
2359 | 0 | case FID_AUTO_CALC: |
2360 | 0 | if ( m_pDocument->GetHardRecalcState() != ScDocument::HardRecalcState::OFF ) |
2361 | 0 | rSet.DisableItem( nWhich ); |
2362 | 0 | else |
2363 | 0 | rSet.Put( SfxBoolItem( nWhich, m_pDocument->GetAutoCalc() ) ); |
2364 | 0 | break; |
2365 | | |
2366 | 0 | case FID_CHG_RECORD: |
2367 | 0 | if ( IsDocShared() ) |
2368 | 0 | rSet.DisableItem( nWhich ); |
2369 | 0 | else |
2370 | 0 | rSet.Put( SfxBoolItem( nWhich, |
2371 | 0 | m_pDocument->GetChangeTrack() != nullptr ) ); |
2372 | 0 | break; |
2373 | | |
2374 | 0 | case SID_CHG_PROTECT: |
2375 | 0 | { |
2376 | 0 | ScChangeTrack* pChangeTrack = m_pDocument->GetChangeTrack(); |
2377 | 0 | if ( pChangeTrack && !IsDocShared() ) |
2378 | 0 | rSet.Put( SfxBoolItem( nWhich, |
2379 | 0 | pChangeTrack->IsProtected() ) ); |
2380 | 0 | else |
2381 | 0 | rSet.DisableItem( nWhich ); |
2382 | 0 | } |
2383 | 0 | break; |
2384 | | |
2385 | 0 | case SID_DOCUMENT_COMPARE: |
2386 | 0 | { |
2387 | 0 | if ( IsDocShared() ) |
2388 | 0 | { |
2389 | 0 | rSet.DisableItem( nWhich ); |
2390 | 0 | } |
2391 | 0 | } |
2392 | 0 | break; |
2393 | | |
2394 | | // When a formula is edited, FID_RECALC must be enabled in any case. Recalc for |
2395 | | // the doc was disabled once because of a bug if AutoCalc was on, but is now |
2396 | | // always enabled because of another bug. |
2397 | | |
2398 | 0 | case SID_TABLES_COUNT: |
2399 | 0 | rSet.Put( SfxInt16Item( nWhich, m_pDocument->GetTableCount() ) ); |
2400 | 0 | break; |
2401 | | |
2402 | 0 | case SID_TABLE_STYLES: |
2403 | 0 | { |
2404 | 0 | ScTableStyles* pStyles = m_pDocument->GetTableStyles(); |
2405 | 0 | if (pStyles) |
2406 | 0 | { |
2407 | 0 | tools::JsonWriter aTree; |
2408 | 0 | pStyles->generateJSON(aTree); |
2409 | 0 | OString aStr = aTree.finishAndGetAsOString(); |
2410 | 0 | rSet.Put( |
2411 | 0 | SfxStringItem( nWhich, OStringToOUString( aStr, RTL_TEXTENCODING_UTF8 ) ) ); |
2412 | 0 | } |
2413 | 0 | } |
2414 | 0 | break; |
2415 | | |
2416 | 0 | case SID_ATTR_YEAR2000 : |
2417 | 0 | rSet.Put( SfxUInt16Item( nWhich, |
2418 | 0 | m_pDocument->GetDocOptions().GetYear2000() ) ); |
2419 | 0 | break; |
2420 | | |
2421 | 0 | case SID_SHARE_DOC: |
2422 | 0 | { |
2423 | 0 | if ( IsReadOnly() || GetObjectShell()->isExportLocked() ) |
2424 | 0 | { |
2425 | 0 | rSet.DisableItem( nWhich ); |
2426 | 0 | } |
2427 | 0 | } |
2428 | 0 | break; |
2429 | 0 | case SID_ATTR_PAGE_ORIENTATION: |
2430 | 0 | case SID_SC_ATTR_PAGE_MARGIN: |
2431 | 0 | case SID_SC_ATTR_PAGE_SIZE: |
2432 | 0 | { |
2433 | 0 | ScViewData* pViewData = GetViewData(); |
2434 | 0 | if (pViewData) |
2435 | 0 | { |
2436 | 0 | ScDocument& rDoc = GetDocument(); |
2437 | 0 | const SCTAB nTab = pViewData->CurrentTabForData(); |
2438 | 0 | OUString aStyleName = rDoc.GetPageStyle(nTab); |
2439 | 0 | ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); |
2440 | 0 | if (pStylePool) |
2441 | 0 | { |
2442 | 0 | SfxStyleSheetBase* pStyleSheet |
2443 | 0 | = pStylePool->Find(aStyleName, SfxStyleFamily::Page); |
2444 | 0 | if (pStyleSheet) |
2445 | 0 | { |
2446 | 0 | const SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); |
2447 | 0 | rSet.Put(rStyleSet.Get(ATTR_PAGE)); |
2448 | 0 | } |
2449 | 0 | } |
2450 | 0 | } |
2451 | 0 | } |
2452 | 0 | break; |
2453 | 0 | case SID_OPEN_HYPERLINK: |
2454 | 0 | { |
2455 | 0 | ScViewData* pViewData = GetViewData(); |
2456 | 0 | if (!pViewData) |
2457 | 0 | { |
2458 | 0 | rSet.DisableItem(nWhich); |
2459 | 0 | break; |
2460 | 0 | } |
2461 | | |
2462 | 0 | if (ScModule::get()->IsEditMode()) |
2463 | 0 | { |
2464 | 0 | if (EditView* pEditView = pViewData->GetEditView(pViewData->GetActivePart())) |
2465 | 0 | if (!URLFieldHelper::IsCursorAtURLField(*pEditView, true)) |
2466 | 0 | rSet.DisableItem(nWhich); |
2467 | 0 | } |
2468 | 0 | else |
2469 | 0 | { |
2470 | 0 | if (ScGridWindow* pWin = pViewData->GetActiveWin()) |
2471 | 0 | { |
2472 | 0 | std::vector<UrlData> vUrls = pWin->GetEditUrls(pViewData->GetCurPos()); |
2473 | 0 | if (vUrls.empty()) |
2474 | 0 | rSet.DisableItem(nWhich); |
2475 | 0 | } |
2476 | 0 | } |
2477 | 0 | } |
2478 | 0 | break; |
2479 | | |
2480 | 0 | case SID_ATTR_CHAR_FONTLIST: |
2481 | 0 | rSet.Put( SvxFontListItem( m_pImpl->pFontList.get(), nWhich ) ); |
2482 | 0 | break; |
2483 | | |
2484 | 0 | case SID_NOTEBOOKBAR: |
2485 | 0 | { |
2486 | 0 | if (SfxBindings* pBindings = GetViewBindings()) |
2487 | 0 | { |
2488 | 0 | bool bVisible = sfx2::SfxNotebookBar::StateMethod(*pBindings, |
2489 | 0 | u"modules/scalc/ui/"); |
2490 | 0 | rSet.Put( SfxBoolItem( SID_NOTEBOOKBAR, bVisible ) ); |
2491 | 0 | } |
2492 | 0 | } |
2493 | 0 | break; |
2494 | | |
2495 | 0 | case SID_LANGUAGE_STATUS: |
2496 | 0 | { |
2497 | 0 | OUString sLanguage; |
2498 | 0 | sal_uInt16 nLangWhich = 0; |
2499 | 0 | LanguageType eLatin = LANGUAGE_DONTKNOW, eCjk = LANGUAGE_DONTKNOW, |
2500 | 0 | eCtl = LANGUAGE_DONTKNOW; |
2501 | |
|
2502 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
2503 | 0 | { |
2504 | 0 | GetDocument().GetLanguage( eLatin, eCjk, eCtl ); |
2505 | 0 | sLanguage = SvtLanguageTable::GetLanguageString(eLatin); |
2506 | |
|
2507 | 0 | if (eLatin == LANGUAGE_NONE) |
2508 | 0 | sLanguage += ";-"; |
2509 | 0 | else |
2510 | 0 | sLanguage += ";" + LanguageTag(eLatin).getBcp47(false); |
2511 | 0 | } |
2512 | 0 | else if (ScTabViewShell* pViewShell = GetBestViewShell()) |
2513 | 0 | { |
2514 | 0 | ScMarkData aMark = pViewShell->GetViewData().GetMarkData(); |
2515 | 0 | SCCOL nCol = pViewShell->GetViewData().GetCurX(); |
2516 | 0 | SCROW nRow = pViewShell->GetViewData().GetCurY(); |
2517 | 0 | SCTAB nTab = pViewShell->GetViewData().CurrentTabForData(); |
2518 | |
|
2519 | 0 | aMark.SetMarkArea(ScRange(nCol, nRow, nTab)); |
2520 | 0 | const ScPatternAttr* pSelAttrs = GetDocument().GetSelectionPattern(aMark); |
2521 | 0 | if (pSelAttrs) |
2522 | 0 | { |
2523 | 0 | const SfxItemSet& rItemSet = pSelAttrs->GetItemSet(); |
2524 | 0 | nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_LANGUAGE); |
2525 | 0 | if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich)) |
2526 | 0 | eLatin = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage(); |
2527 | |
|
2528 | 0 | nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_CJK_LANGUAGE); |
2529 | 0 | if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich)) |
2530 | 0 | eCjk = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage(); |
2531 | |
|
2532 | 0 | nLangWhich = rItemSet.GetPool()->GetWhichIDFromSlotID(SID_ATTR_CHAR_CTL_LANGUAGE); |
2533 | 0 | if (SfxItemState::SET == rItemSet.GetItemState(nLangWhich)) |
2534 | 0 | eCtl = static_cast<const SvxLanguageItem&>(rItemSet.Get(nLangWhich)).GetLanguage(); |
2535 | |
|
2536 | 0 | if (eLatin != LANGUAGE_DONTKNOW) |
2537 | 0 | sLanguage = SvtLanguageTable::GetLanguageString(eLatin); |
2538 | 0 | else if (eCjk != LANGUAGE_DONTKNOW) |
2539 | 0 | sLanguage = SvtLanguageTable::GetLanguageString(eCjk); |
2540 | 0 | else if (eCtl != LANGUAGE_DONTKNOW) |
2541 | 0 | sLanguage = SvtLanguageTable::GetLanguageString(eCtl); |
2542 | |
|
2543 | 0 | if (sLanguage.isEmpty()) |
2544 | 0 | { |
2545 | 0 | GetDocument().GetLanguage(eLatin, eCjk, eCtl); |
2546 | 0 | sLanguage = SvtLanguageTable::GetLanguageString(eLatin); |
2547 | 0 | } |
2548 | 0 | } |
2549 | 0 | } |
2550 | 0 | rSet.Put(SfxStringItem(nWhich, sLanguage)); |
2551 | 0 | } |
2552 | 0 | break; |
2553 | 0 | case SID_PROTECTPOS: |
2554 | 0 | case SID_PROTECTSIZE: |
2555 | 0 | { |
2556 | 0 | ScViewData* pViewData = GetViewData(); |
2557 | 0 | if (pViewData) |
2558 | 0 | { |
2559 | 0 | const ScDrawView* pDrView = pViewData->GetScDrawView(); |
2560 | 0 | const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList(); |
2561 | 0 | if ( rMarkList.GetMarkCount() == 1 ) |
2562 | 0 | { |
2563 | 0 | const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); |
2564 | 0 | const SdrObjKind nSdrObjKind = pObj->GetObjIdentifier(); |
2565 | |
|
2566 | 0 | if ( nSdrObjKind == SdrObjKind::Graphic ) |
2567 | 0 | { |
2568 | 0 | if (nWhich == SID_PROTECTSIZE) |
2569 | 0 | { |
2570 | 0 | rSet.Put(SfxBoolItem(nWhich, pObj->IsResizeProtect())); |
2571 | 0 | if (pObj->IsMoveProtect()) |
2572 | 0 | rSet.DisableItem( nWhich ); |
2573 | 0 | } |
2574 | 0 | else |
2575 | 0 | rSet.Put(SfxBoolItem(nWhich, pObj->IsMoveProtect())); |
2576 | |
|
2577 | 0 | break; |
2578 | 0 | } |
2579 | 0 | } |
2580 | 0 | } |
2581 | 0 | rSet.DisableItem( nWhich ); |
2582 | 0 | } |
2583 | 0 | break; |
2584 | 0 | default: |
2585 | 0 | { |
2586 | 0 | } |
2587 | 0 | break; |
2588 | 0 | } |
2589 | 0 | } |
2590 | 0 | } |
2591 | | |
2592 | | void ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect, bool /*bOutputToWindow*/ ) |
2593 | 0 | { |
2594 | |
|
2595 | 0 | SCTAB nVisTab = m_pDocument->GetVisibleTab(); |
2596 | 0 | if (!m_pDocument->HasTable(nVisTab)) |
2597 | 0 | return; |
2598 | | |
2599 | 0 | vcl::text::ComplexTextLayoutFlags nOldLayoutMode = pDev->GetLayoutMode(); |
2600 | 0 | pDev->SetLayoutMode( vcl::text::ComplexTextLayoutFlags::Default ); // even if it's the same, to get the metafile action |
2601 | |
|
2602 | 0 | if ( nAspect == ASPECT_THUMBNAIL ) |
2603 | 0 | { |
2604 | 0 | tools::Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL ); |
2605 | 0 | ScViewData aTmpData( *this, nullptr ); |
2606 | 0 | aTmpData.SetTabNo(nVisTab); |
2607 | 0 | SnapVisArea( aBoundRect ); |
2608 | 0 | aTmpData.SetScreen( aBoundRect ); |
2609 | 0 | ScPrintFunc::DrawToDev( *m_pDocument, pDev, 1.0, aBoundRect, aTmpData, true ); |
2610 | 0 | } |
2611 | 0 | else |
2612 | 0 | { |
2613 | 0 | tools::Rectangle aOldArea = SfxObjectShell::GetVisArea(); |
2614 | 0 | tools::Rectangle aNewArea = aOldArea; |
2615 | 0 | ScViewData aTmpData( *this, nullptr ); |
2616 | 0 | aTmpData.SetTabNo(nVisTab); |
2617 | 0 | SnapVisArea( aNewArea ); |
2618 | 0 | if ( aNewArea != aOldArea && (m_pDocument->GetPosLeft() > 0 || m_pDocument->GetPosTop() > 0) ) |
2619 | 0 | SfxObjectShell::SetVisArea( aNewArea ); |
2620 | 0 | aTmpData.SetScreen( aNewArea ); |
2621 | 0 | ScPrintFunc::DrawToDev( *m_pDocument, pDev, 1.0, aNewArea, aTmpData, true ); |
2622 | 0 | } |
2623 | |
|
2624 | 0 | pDev->SetLayoutMode( nOldLayoutMode ); |
2625 | 0 | } |
2626 | | |
2627 | | tools::Rectangle ScDocShell::GetVisArea( sal_uInt16 nAspect ) const |
2628 | 0 | { |
2629 | 0 | SfxObjectCreateMode eShellMode = GetCreateMode(); |
2630 | 0 | if ( eShellMode == SfxObjectCreateMode::ORGANIZER ) |
2631 | 0 | { |
2632 | | // without contents we also don't know how large are the contents; |
2633 | | // return empty rectangle, it will then be calculated after the loading |
2634 | 0 | return tools::Rectangle(); |
2635 | 0 | } |
2636 | | |
2637 | 0 | if( nAspect == ASPECT_THUMBNAIL ) |
2638 | 0 | { |
2639 | 0 | SCTAB nVisTab = m_pDocument->GetVisibleTab(); |
2640 | 0 | if (!m_pDocument->HasTable(nVisTab)) |
2641 | 0 | { |
2642 | 0 | nVisTab = 0; |
2643 | 0 | const_cast<ScDocShell*>(this)->m_pDocument->SetVisibleTab(nVisTab); |
2644 | 0 | } |
2645 | 0 | Size aSize = m_pDocument->GetPageSize(nVisTab); |
2646 | 0 | const tools::Long SC_PREVIEW_SIZE_X = 10000; |
2647 | 0 | const tools::Long SC_PREVIEW_SIZE_Y = 12400; |
2648 | 0 | tools::Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X, SC_PREVIEW_SIZE_Y); |
2649 | 0 | if (aSize.Width() > aSize.Height()) |
2650 | 0 | { |
2651 | 0 | aArea.SetRight( SC_PREVIEW_SIZE_Y ); |
2652 | 0 | aArea.SetBottom( SC_PREVIEW_SIZE_X ); |
2653 | 0 | } |
2654 | |
|
2655 | 0 | bool bNegativePage = m_pDocument->IsNegativePage( m_pDocument->GetVisibleTab() ); |
2656 | 0 | if ( bNegativePage ) |
2657 | 0 | ScDrawLayer::MirrorRectRTL( aArea ); |
2658 | 0 | SnapVisArea( aArea ); |
2659 | 0 | return aArea; |
2660 | 0 | } |
2661 | 0 | else if( nAspect == ASPECT_CONTENT && eShellMode != SfxObjectCreateMode::EMBEDDED ) |
2662 | 0 | { |
2663 | | // fetch visarea like after loading |
2664 | |
|
2665 | 0 | SCTAB nVisTab = m_pDocument->GetVisibleTab(); |
2666 | 0 | if (!m_pDocument->HasTable(nVisTab)) |
2667 | 0 | { |
2668 | 0 | nVisTab = 0; |
2669 | 0 | const_cast<ScDocShell*>(this)->m_pDocument->SetVisibleTab(nVisTab); |
2670 | 0 | } |
2671 | 0 | SCCOL nStartCol; |
2672 | 0 | SCROW nStartRow; |
2673 | 0 | m_pDocument->GetDataStart( nVisTab, nStartCol, nStartRow ); |
2674 | 0 | SCCOL nEndCol; |
2675 | 0 | SCROW nEndRow; |
2676 | 0 | m_pDocument->GetPrintArea( nVisTab, nEndCol, nEndRow ); |
2677 | 0 | if (nStartCol>nEndCol) |
2678 | 0 | nStartCol = nEndCol; |
2679 | 0 | if (nStartRow>nEndRow) |
2680 | 0 | nStartRow = nEndRow; |
2681 | 0 | tools::Rectangle aNewArea = m_pDocument |
2682 | 0 | ->GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab ); |
2683 | 0 | return aNewArea; |
2684 | 0 | } |
2685 | 0 | else |
2686 | 0 | return SfxObjectShell::GetVisArea( nAspect ); |
2687 | 0 | } |
2688 | | |
2689 | | namespace { |
2690 | | |
2691 | | [[nodiscard]] |
2692 | | tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol ) |
2693 | 66.4k | { |
2694 | 66.4k | SCCOL nCol = 0; |
2695 | 66.4k | tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); |
2696 | 66.4k | tools::Long nSnap = 0; |
2697 | 20.5M | while ( nCol<rDoc.MaxCol() ) |
2698 | 20.5M | { |
2699 | 20.5M | tools::Long nAdd = rDoc.GetColWidth(nCol, nTab); |
2700 | 20.5M | if ( nSnap + nAdd/2 < nTwips || nCol < rStartCol ) |
2701 | 20.4M | { |
2702 | 20.4M | nSnap += nAdd; |
2703 | 20.4M | ++nCol; |
2704 | 20.4M | } |
2705 | 65.4k | else |
2706 | 65.4k | break; |
2707 | 20.5M | } |
2708 | 66.4k | nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); |
2709 | 66.4k | rStartCol = nCol; |
2710 | 66.4k | return nVal; |
2711 | 66.4k | } |
2712 | | |
2713 | | [[nodiscard]] |
2714 | | tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow ) |
2715 | 66.4k | { |
2716 | 66.4k | SCROW nRow = 0; |
2717 | 66.4k | tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); |
2718 | 66.4k | tools::Long nSnap = 0; |
2719 | | |
2720 | 66.4k | bool bFound = false; |
2721 | 51.0M | for (SCROW i = nRow; i <= rDoc.MaxRow(); ++i) |
2722 | 51.0M | { |
2723 | 51.0M | SCROW nLastRow; |
2724 | 51.0M | if (rDoc.RowHidden(i, nTab, nullptr, &nLastRow)) |
2725 | 304 | { |
2726 | 304 | i = nLastRow; |
2727 | 304 | continue; |
2728 | 304 | } |
2729 | | |
2730 | 51.0M | nRow = i; |
2731 | 51.0M | tools::Long nAdd = rDoc.GetRowHeight(i, nTab); |
2732 | 51.0M | if ( nSnap + nAdd/2 < nTwips || nRow < rStartRow ) |
2733 | 50.9M | { |
2734 | 50.9M | nSnap += nAdd; |
2735 | 50.9M | ++nRow; |
2736 | 50.9M | } |
2737 | 66.2k | else |
2738 | 66.2k | { |
2739 | 66.2k | bFound = true; |
2740 | 66.2k | break; |
2741 | 66.2k | } |
2742 | 51.0M | } |
2743 | 66.4k | if (!bFound) |
2744 | 159 | nRow = rDoc.MaxRow(); // all hidden down to the bottom |
2745 | | |
2746 | 66.4k | nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); |
2747 | 66.4k | rStartRow = nRow; |
2748 | 66.4k | return nVal; |
2749 | 66.4k | } |
2750 | | |
2751 | | } |
2752 | | |
2753 | | void ScDocShell::SnapVisArea( tools::Rectangle& rRect ) const |
2754 | 33.2k | { |
2755 | 33.2k | SCTAB nTab = m_pDocument->GetVisibleTab(); |
2756 | 33.2k | tools::Long nOrigTop = rRect.Top(); |
2757 | 33.2k | tools::Long nOrigLeft = rRect.Left(); |
2758 | 33.2k | bool bNegativePage = m_pDocument->IsNegativePage( nTab ); |
2759 | 33.2k | if ( bNegativePage ) |
2760 | 11 | ScDrawLayer::MirrorRectRTL( rRect ); // calculate with positive (LTR) values |
2761 | | |
2762 | 33.2k | SCCOL nCol = m_pDocument->GetPosLeft(); |
2763 | 33.2k | tools::Long nSetLeft = SnapHorizontal( *m_pDocument, nTab, rRect.Left(), nCol ); |
2764 | 33.2k | rRect.SetLeft( nSetLeft ); |
2765 | 33.2k | ++nCol; // at least one column |
2766 | 33.2k | tools::Long nCorrectionLeft = (nOrigLeft == 0 && nCol > 0) ? nSetLeft : 0; // initial correction |
2767 | 33.2k | rRect.SetRight( SnapHorizontal( *m_pDocument, nTab, rRect.Right() + nCorrectionLeft, nCol )); |
2768 | | |
2769 | 33.2k | SCROW nRow = m_pDocument->GetPosTop(); |
2770 | 33.2k | tools::Long nSetTop = SnapVertical( *m_pDocument, nTab, rRect.Top(), nRow ); |
2771 | 33.2k | rRect.SetTop( nSetTop ); |
2772 | 33.2k | ++nRow; // at least one row |
2773 | 33.2k | tools::Long nCorrectionTop = (nOrigTop == 0 && nRow > 0) ? nSetTop : 0; // initial correction |
2774 | 33.2k | rRect.SetBottom( SnapVertical( *m_pDocument, nTab, rRect.Bottom() + nCorrectionTop, nRow )); |
2775 | | |
2776 | 33.2k | if ( bNegativePage ) |
2777 | 11 | ScDrawLayer::MirrorRectRTL( rRect ); // back to real rectangle |
2778 | 33.2k | } |
2779 | | |
2780 | | #if defined(_WIN32) |
2781 | | bool ScDocShell::DdeGetData( const OUString& rItem, |
2782 | | const OUString& rMimeType, |
2783 | | css::uno::Any & rValue ) |
2784 | | { |
2785 | | SotClipboardFormatId eFormatId = SotExchange::GetFormatIdFromMimeType( rMimeType ); |
2786 | | if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId) |
2787 | | { |
2788 | | if( rItem.equalsIgnoreAsciiCase( "Format" ) ) |
2789 | | { |
2790 | | OString aFmtByte(OUStringToOString(m_aDdeTextFmt, |
2791 | | osl_getThreadTextEncoding())); |
2792 | | rValue <<= css::uno::Sequence< sal_Int8 >( |
2793 | | reinterpret_cast<const sal_Int8*>(aFmtByte.getStr()), |
2794 | | aFmtByte.getLength() + 1 ); |
2795 | | return true; |
2796 | | } |
2797 | | ScImportExport aObj( *m_pDocument, rItem ); |
2798 | | if ( !aObj.IsRef() ) |
2799 | | return false; // invalid range |
2800 | | |
2801 | | if( m_aDdeTextFmt[0] == 'F' ) |
2802 | | aObj.SetFormulas( true ); |
2803 | | if( m_aDdeTextFmt == "SYLK" || |
2804 | | m_aDdeTextFmt == "FSYLK" ) |
2805 | | { |
2806 | | OString aData; |
2807 | | if( aObj.ExportByteString( aData, osl_getThreadTextEncoding(), |
2808 | | SotClipboardFormatId::SYLK ) ) |
2809 | | { |
2810 | | rValue <<= css::uno::Sequence< sal_Int8 >( |
2811 | | reinterpret_cast<const sal_Int8*>(aData.getStr()), |
2812 | | aData.getLength() + 1 ); |
2813 | | return true; |
2814 | | } |
2815 | | else |
2816 | | return false; |
2817 | | } |
2818 | | if( m_aDdeTextFmt == "CSV" || |
2819 | | m_aDdeTextFmt == "FCSV" ) |
2820 | | aObj.SetSeparator( ',' ); |
2821 | | aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) ); |
2822 | | return aObj.ExportData( rMimeType, rValue ); |
2823 | | } |
2824 | | |
2825 | | ScImportExport aObj( *m_pDocument, rItem ); |
2826 | | aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) ); |
2827 | | return aObj.IsRef() && aObj.ExportData( rMimeType, rValue ); |
2828 | | } |
2829 | | |
2830 | | bool ScDocShell::DdeSetData( const OUString& rItem, |
2831 | | const OUString& rMimeType, |
2832 | | const css::uno::Any & rValue ) |
2833 | | { |
2834 | | SotClipboardFormatId eFormatId = SotExchange::GetFormatIdFromMimeType( rMimeType ); |
2835 | | if (SotClipboardFormatId::STRING == eFormatId || SotClipboardFormatId::STRING_TSVC == eFormatId) |
2836 | | { |
2837 | | if( rItem.equalsIgnoreAsciiCase( "Format" ) ) |
2838 | | { |
2839 | | if ( ScByteSequenceToString::GetString( m_aDdeTextFmt, rValue ) ) |
2840 | | { |
2841 | | m_aDdeTextFmt = m_aDdeTextFmt.toAsciiUpperCase(); |
2842 | | return true; |
2843 | | } |
2844 | | return false; |
2845 | | } |
2846 | | ScImportExport aObj( *m_pDocument, rItem ); |
2847 | | if( m_aDdeTextFmt[0] == 'F' ) |
2848 | | aObj.SetFormulas( true ); |
2849 | | if( m_aDdeTextFmt == "SYLK" || |
2850 | | m_aDdeTextFmt == "FSYLK" ) |
2851 | | { |
2852 | | OUString aData; |
2853 | | if ( ScByteSequenceToString::GetString( aData, rValue ) ) |
2854 | | { |
2855 | | return aObj.ImportString( aData, SotClipboardFormatId::SYLK ); |
2856 | | } |
2857 | | return false; |
2858 | | } |
2859 | | if( m_aDdeTextFmt == "CSV" || |
2860 | | m_aDdeTextFmt == "FCSV" ) |
2861 | | aObj.SetSeparator( ',' ); |
2862 | | OSL_ENSURE( false, "Implementation is missing" ); |
2863 | | return false; |
2864 | | } |
2865 | | /*ScImportExport aObj( aDocument, rItem ); |
2866 | | return aObj.IsRef() && ScImportExport::ImportData( rMimeType, rValue );*/ |
2867 | | OSL_ENSURE( false, "Implementation is missing" ); |
2868 | | return false; |
2869 | | } |
2870 | | #endif |
2871 | | |
2872 | | ::sfx2::SvLinkSource* ScDocShell::DdeCreateLinkSource( const OUString& rItem ) |
2873 | 0 | { |
2874 | 0 | if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()) |
2875 | 0 | return nullptr; |
2876 | | |
2877 | | // only check for valid item string - range is parsed again in ScServerObject ctor |
2878 | | |
2879 | | // named range? |
2880 | 0 | OUString aPos = rItem; |
2881 | 0 | ScRangeName& rRange = m_pDocument->GetRangeName(); |
2882 | 0 | const ScRangeData* pData = rRange.findByUpperName(ScGlobal::getCharClass().uppercase(aPos)); |
2883 | 0 | if (pData) |
2884 | 0 | { |
2885 | 0 | if( pData->HasType( ScRangeData::Type::RefArea ) |
2886 | 0 | || pData->HasType( ScRangeData::Type::AbsArea ) |
2887 | 0 | || pData->HasType( ScRangeData::Type::AbsPos ) ) |
2888 | 0 | aPos = pData->GetSymbol(); // continue with the name's contents |
2889 | 0 | } |
2890 | | |
2891 | | // Address in DDE function must be always parsed as CONV_OOO so that it |
2892 | | // would always work regardless of current address conversion. We do this |
2893 | | // because the address item in a DDE entry is *not* normalized when saved |
2894 | | // into ODF. |
2895 | 0 | ScRange aRange; |
2896 | 0 | bool bValid = ( (aRange.Parse(aPos, *m_pDocument, formula::FormulaGrammar::CONV_OOO ) & ScRefFlags::VALID) || |
2897 | 0 | (aRange.aStart.Parse(aPos, *m_pDocument, formula::FormulaGrammar::CONV_OOO) & ScRefFlags::VALID) ); |
2898 | |
|
2899 | 0 | ScServerObject* pObj = nullptr; // NULL = error |
2900 | 0 | if ( bValid ) |
2901 | 0 | pObj = new ScServerObject( this, rItem ); |
2902 | | |
2903 | | // GetLinkManager()->InsertServer() is in the ScServerObject ctor |
2904 | |
|
2905 | 0 | return pObj; |
2906 | 0 | } |
2907 | | |
2908 | | void ScDocShell::LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument& rDocument, const ScAddress& rPos, const ScPostIt* pNote) |
2909 | 0 | { |
2910 | 0 | if ( !rDocument.IsDocVisible() || // don't want callbacks until document load |
2911 | 0 | !comphelper::LibreOfficeKit::isActive() || |
2912 | 0 | comphelper::LibreOfficeKit::isTiledAnnotations() ) |
2913 | 0 | return; |
2914 | | |
2915 | 0 | tools::JsonWriter aAnnotation; |
2916 | 0 | { |
2917 | 0 | auto commentNode = aAnnotation.startNode("comment"); |
2918 | 0 | aAnnotation.put("action", (nType == LOKCommentNotificationType::Add ? "Add" : |
2919 | 0 | (nType == LOKCommentNotificationType::Remove ? "Remove" : |
2920 | 0 | (nType == LOKCommentNotificationType::Modify ? "Modify" : "???")))); |
2921 | |
|
2922 | 0 | assert(pNote); |
2923 | 0 | aAnnotation.put("id", pNote->GetId()); |
2924 | 0 | aAnnotation.put("tab", rPos.Tab()); |
2925 | |
|
2926 | 0 | if (nType != LOKCommentNotificationType::Remove) |
2927 | 0 | { |
2928 | 0 | aAnnotation.put("author", pNote->GetAuthor()); |
2929 | 0 | aAnnotation.put("dateTime", pNote->GetDate()); |
2930 | 0 | if (const auto* pData = pNote->GetThreadedCommentData()) |
2931 | 0 | { |
2932 | 0 | aAnnotation.put("text", pData->maRoot.maText); |
2933 | 0 | aAnnotation.put("threaded", "true"); |
2934 | 0 | aAnnotation.put("resolved", pNote->IsResolved() ? "true" : "false"); |
2935 | 0 | } |
2936 | 0 | else |
2937 | 0 | aAnnotation.put("text", pNote->GetText()); |
2938 | | |
2939 | | // Calculating the cell cursor position |
2940 | 0 | ScViewData* pViewData = GetViewData(); |
2941 | 0 | if (pViewData && pViewData->GetActiveWin()) |
2942 | 0 | aAnnotation.put("cellRange", ScPostIt::NoteRangeToJsonString(rDocument, rPos)); |
2943 | 0 | } |
2944 | 0 | } |
2945 | |
|
2946 | 0 | OString aPayload = aAnnotation.finishAndGetAsOString(); |
2947 | |
|
2948 | 0 | ScViewData* pViewData = GetViewData(); |
2949 | 0 | SfxViewShell* pThisViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr ); |
2950 | 0 | SfxViewShell* pViewShell = SfxViewShell::GetFirst(); |
2951 | 0 | while (pViewShell) |
2952 | 0 | { |
2953 | 0 | if (pThisViewShell == nullptr || pViewShell->GetDocId() == pThisViewShell->GetDocId()) |
2954 | 0 | pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_COMMENT, aPayload); |
2955 | 0 | pViewShell = SfxViewShell::GetNext(*pViewShell); |
2956 | 0 | } |
2957 | 0 | } |
2958 | | |
2959 | | ScViewData* ScDocShell::GetViewData() |
2960 | 3.57k | { |
2961 | 3.57k | SfxViewShell* pCur = SfxViewShell::Current(); |
2962 | 3.57k | ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pCur ); |
2963 | 3.57k | return pViewSh ? &pViewSh->GetViewData() : nullptr; |
2964 | 3.57k | } |
2965 | | |
2966 | | SCTAB ScDocShell::GetCurTab() |
2967 | 0 | { |
2968 | | //! this must be made non-static and use a ViewShell from this document! |
2969 | |
|
2970 | 0 | ScViewData* pViewData = GetViewData(); |
2971 | |
|
2972 | 0 | return pViewData ? pViewData->CurrentTabForData() : static_cast<SCTAB>(0); |
2973 | 0 | } |
2974 | | |
2975 | | ScTabViewShell* ScDocShell::GetBestViewShell( bool bOnlyVisible ) |
2976 | 194k | { |
2977 | 194k | ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); |
2978 | | // wrong Doc? |
2979 | 194k | if( pViewSh && pViewSh->GetViewData().GetDocShell() != this ) |
2980 | 0 | pViewSh = nullptr; |
2981 | 194k | if( !pViewSh ) |
2982 | 194k | { |
2983 | | // 1. find ViewShell |
2984 | 194k | SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible ); |
2985 | 194k | if( pFrame ) |
2986 | 0 | { |
2987 | 0 | SfxViewShell* p = pFrame->GetViewShell(); |
2988 | 0 | pViewSh = dynamic_cast< ScTabViewShell *>( p ); |
2989 | 0 | } |
2990 | 194k | } |
2991 | 194k | return pViewSh; |
2992 | 194k | } |
2993 | | |
2994 | | SfxBindings* ScDocShell::GetViewBindings() |
2995 | 185k | { |
2996 | | // used to invalidate slots after changes to this document |
2997 | | |
2998 | 185k | SfxViewShell* pViewSh = GetBestViewShell(); |
2999 | 185k | if (pViewSh) |
3000 | 0 | return &pViewSh->GetViewFrame().GetBindings(); |
3001 | 185k | else |
3002 | 185k | return nullptr; |
3003 | 185k | } |
3004 | | |
3005 | | ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo ) // static |
3006 | 0 | { |
3007 | 0 | ScDocShell* pFound = nullptr; |
3008 | 0 | SfxObjectShell* pShell = SfxObjectShell::GetFirst(); |
3009 | 0 | sal_uInt16 nShellCnt = 0; |
3010 | |
|
3011 | 0 | while ( pShell && !pFound ) |
3012 | 0 | { |
3013 | 0 | if ( auto pDocSh = dynamic_cast<ScDocShell*>(pShell) ) |
3014 | 0 | { |
3015 | 0 | if ( nShellCnt == nDocNo ) |
3016 | 0 | pFound = pDocSh; |
3017 | 0 | else |
3018 | 0 | ++nShellCnt; |
3019 | 0 | } |
3020 | 0 | pShell = SfxObjectShell::GetNext( *pShell ); |
3021 | 0 | } |
3022 | |
|
3023 | 0 | return pFound; |
3024 | 0 | } |
3025 | | |
3026 | | IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void ) |
3027 | 0 | { |
3028 | 0 | assert( _pFileDlg && "ScDocShell::DialogClosedHdl(): no file dialog"); |
3029 | 0 | OSL_ENSURE( m_pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" ); |
3030 | |
|
3031 | 0 | if ( ERRCODE_NONE == _pFileDlg->GetError() ) |
3032 | 0 | { |
3033 | 0 | sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot(); |
3034 | 0 | std::unique_ptr<SfxMedium> pMed = m_pImpl->pDocInserter->CreateMedium(); |
3035 | | // #i87094# If a .odt was selected pMed is NULL. |
3036 | 0 | if (pMed) |
3037 | 0 | { |
3038 | 0 | m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); |
3039 | 0 | if ( SID_DOCUMENT_COMPARE == nSlot ) |
3040 | 0 | { |
3041 | 0 | if ( pMed->GetFilter() ) |
3042 | 0 | m_pImpl->pRequest->AppendItem( |
3043 | 0 | SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); |
3044 | 0 | OUString sOptions = ScDocumentLoader::GetOptions( *pMed ); |
3045 | 0 | if ( !sOptions.isEmpty() ) |
3046 | 0 | m_pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) ); |
3047 | 0 | } |
3048 | 0 | const SfxPoolItem* pItem = nullptr; |
3049 | 0 | const SfxInt16Item* pInt16Item(nullptr); |
3050 | 0 | if (pMed->GetItemSet().GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET) |
3051 | 0 | { |
3052 | 0 | pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem); |
3053 | 0 | } |
3054 | 0 | if (pInt16Item) |
3055 | 0 | { |
3056 | 0 | m_pImpl->pRequest->AppendItem( *pItem ); |
3057 | 0 | } |
3058 | |
|
3059 | 0 | Execute( *(m_pImpl->pRequest) ); |
3060 | 0 | } |
3061 | 0 | } |
3062 | |
|
3063 | 0 | m_pImpl->bIgnoreLostRedliningWarning = false; |
3064 | 0 | } |
3065 | | |
3066 | | #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT |
3067 | | |
3068 | | void ScDocShell::EnableSharedSettings( bool bEnable ) |
3069 | | { |
3070 | | SetDocumentModified(); |
3071 | | |
3072 | | if ( bEnable ) |
3073 | | { |
3074 | | m_pDocument->EndChangeTracking(); |
3075 | | m_pDocument->StartChangeTracking(); |
3076 | | |
3077 | | // hide accept or reject changes dialog |
3078 | | sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId(); |
3079 | | SfxViewFrame* pViewFrame = SfxViewFrame::Current(); |
3080 | | if ( pViewFrame && pViewFrame->HasChildWindow( nId ) ) |
3081 | | { |
3082 | | pViewFrame->ToggleChildWindow( nId ); |
3083 | | SfxBindings* pBindings = GetViewBindings(); |
3084 | | if ( pBindings ) |
3085 | | { |
3086 | | pBindings->Invalidate( FID_CHG_ACCEPT ); |
3087 | | } |
3088 | | } |
3089 | | } |
3090 | | else |
3091 | | { |
3092 | | m_pDocument->EndChangeTracking(); |
3093 | | } |
3094 | | |
3095 | | ScChangeViewSettings aChangeViewSet; |
3096 | | aChangeViewSet.SetShowChanges( false ); |
3097 | | m_pDocument->SetChangeViewSettings( aChangeViewSet ); |
3098 | | } |
3099 | | |
3100 | | uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument() |
3101 | | { |
3102 | | uno::Reference< frame::XModel > xModel; |
3103 | | ScModule* mod = ScModule::get(); |
3104 | | try |
3105 | | { |
3106 | | mod->SetInSharedDocLoading(true); |
3107 | | uno::Reference< frame::XDesktop2 > xLoader = frame::Desktop::create( ::comphelper::getProcessComponentContext() ); |
3108 | | uno::Sequence aArgs{ comphelper::makePropertyValue(u"Hidden"_ustr, true) }; |
3109 | | |
3110 | | if ( GetMedium() ) |
3111 | | { |
3112 | | const SfxStringItem* pPasswordItem = GetMedium()->GetItemSet().GetItem(SID_PASSWORD, false); |
3113 | | if ( pPasswordItem && !pPasswordItem->GetValue().isEmpty() ) |
3114 | | { |
3115 | | aArgs.realloc( 2 ); |
3116 | | auto pArgs = aArgs.getArray(); |
3117 | | pArgs[1].Name = "Password"; |
3118 | | pArgs[1].Value <<= pPasswordItem->GetValue(); |
3119 | | } |
3120 | | const SfxUnoAnyItem* pEncryptionItem = GetMedium()->GetItemSet().GetItem(SID_ENCRYPTIONDATA, false); |
3121 | | if (pEncryptionItem) |
3122 | | { |
3123 | | aArgs.realloc(aArgs.getLength() + 1); |
3124 | | auto pArgs = aArgs.getArray(); |
3125 | | pArgs[aArgs.getLength() - 1].Name = "EncryptionData"; |
3126 | | pArgs[aArgs.getLength() - 1].Value = pEncryptionItem->GetValue(); |
3127 | | } |
3128 | | } |
3129 | | |
3130 | | xModel.set( |
3131 | | xLoader->loadComponentFromURL( GetSharedFileURL(), u"_blank"_ustr, 0, aArgs ), |
3132 | | uno::UNO_QUERY_THROW ); |
3133 | | mod->SetInSharedDocLoading(false); |
3134 | | } |
3135 | | catch ( uno::Exception& ) |
3136 | | { |
3137 | | OSL_FAIL( "ScDocShell::LoadSharedDocument(): caught exception" ); |
3138 | | mod->SetInSharedDocLoading(false); |
3139 | | try |
3140 | | { |
3141 | | uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW ); |
3142 | | xClose->close( true ); |
3143 | | return uno::Reference< frame::XModel >(); |
3144 | | } |
3145 | | catch ( uno::Exception& ) |
3146 | | { |
3147 | | return uno::Reference< frame::XModel >(); |
3148 | | } |
3149 | | } |
3150 | | return xModel; |
3151 | | } |
3152 | | |
3153 | | #endif |
3154 | | |
3155 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |