1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
21 #include <comphelper/lok.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <scitems.hxx>
24 #include <sfx2/app.hxx>
26 #include <editeng/flditem.hxx>
27 #include <editeng/outliner.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/objface.hxx>
32 #include <IAnyRefDialog.hxx>
34 #include <svtools/ehdl.hxx>
35 #include <svtools/accessibilityoptions.hxx>
36 #include <svl/ctloptions.hxx>
37 #include <unotools/useroptions.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/request.hxx>
40 #include <sfx2/printer.hxx>
41 #include <editeng/langitem.hxx>
42 #include <svtools/colorcfg.hxx>
44 #include <svl/whiter.hxx>
45 #include <svx/dialogs.hrc>
46 #include <svl/inethist.hxx>
47 #include <vcl/svapp.hxx>
48 #include <svx/svxerr.hxx>
49 #include <comphelper/diagnose_ex.hxx>
51 #include <editeng/unolingu.hxx>
52 #include <unotools/lingucfg.hxx>
53 #include <i18nlangtag/mslangid.hxx>
54 #include <i18nlangtag/languagetag.hxx>
55 #include <com/sun/star/i18n/ScriptType.hpp>
56 #include <com/sun/star/linguistic2/XThesaurus.hpp>
57 #include <ooo/vba/XSinkCaller.hpp>
61 #include <viewopti.hxx>
62 #include <docoptio.hxx>
63 #include <appoptio.hxx>
64 #include <defaultsoptions.hxx>
65 #include <formulaopt.hxx>
66 #include <inputopt.hxx>
67 #include <printopt.hxx>
68 #include <navicfg.hxx>
69 #include <addincfg.hxx>
70 #include <tabvwsh.hxx>
71 #include <prevwsh.hxx>
73 #include <drwlayer.hxx>
74 #include <uiitems.hxx>
76 #include <scerrors.hrc>
77 #include <scstyles.hrc>
78 #include <globstr.hrc>
79 #include <scresid.hxx>
80 #include <bitmaps.hlst>
81 #include <inputhdl.hxx>
82 #include <inputwin.hxx>
83 #include <msgpool.hxx>
84 #include <detfunc.hxx>
85 #include <preview.hxx>
86 #include <dragdata.hxx>
87 #include <markdata.hxx>
88 #include <transobj.hxx>
89 #include <funcdesc.hxx>
91 #define ShellClass_ScModule
92 #include <scslots.hxx>
94 #include <scabstdlg.hxx>
95 #include <formula/errorcodes.hxx>
96 #include <documentlinkmgr.hxx>
97 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
98 #include <sfx2/lokhelper.hxx>
100 #define SC_IDLE_MIN 150
101 #define SC_IDLE_MAX 3000
102 #define SC_IDLE_STEP 75
103 #define SC_IDLE_COUNT 50
105 static sal_uInt16 nIdleCount
= 0;
107 SFX_IMPL_INTERFACE(ScModule
, SfxShell
)
109 void ScModule::InitInterface_Impl()
111 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION
,
112 SfxVisibilityFlags::Standard
| SfxVisibilityFlags::Client
| SfxVisibilityFlags::Viewer
,
113 ToolbarId::Objectbar_App
);
115 GetStaticInterface()->RegisterStatusBar(StatusBarId::CalcStatusBar
);
118 ScModule::ScModule( SfxObjectFactory
* pFact
) :
119 SfxModule("sc"_ostr
, {pFact
}),
120 m_aIdleTimer("sc ScModule IdleTimer"),
121 m_pDragData(new ScDragData
),
122 m_pSelTransfer( nullptr ),
123 m_pRefInputHandler( nullptr ),
125 m_bIsWaterCan( false ),
126 m_bIsInEditCommand( false ),
127 m_bIsInExecuteDrop( false ),
128 m_bIsInSharedDocLoading( false ),
129 m_bIsInSharedDocSaving( false )
131 // The ResManager (DLL data) is not yet initialized in the ctor!
132 SetName(u
"StarCalc"_ustr
); // for Basic
136 // InputHandler does not need to be created
138 // Create ErrorHandler - was in Init()
139 // Between OfficeApplication::Init and ScGlobal::Init
140 SvxErrorHandler::ensure();
141 m_pErrorHdl
.reset( new SfxErrorHandler(RID_ERRHDLSC
,
146 m_aIdleTimer
.SetTimeout(SC_IDLE_MIN
);
147 m_aIdleTimer
.SetInvokeHandler( LINK( this, ScModule
, IdleHandler
) );
148 m_aIdleTimer
.Start();
150 m_pMessagePool
= new ScMessagePool
;
151 SetPool( m_pMessagePool
.get() );
153 ScGlobal::InitTextHeight( *m_pMessagePool
);
155 StartListening( *SfxGetpApp() ); // for SfxHintId::Deinitializing
157 // Initialize the color config
161 ScModule::~ScModule()
163 OSL_ENSURE( !m_pSelTransfer
, "Selection Transfer object not deleted" );
165 // InputHandler does not need to be deleted (there's none in the App anymore)
167 m_pMessagePool
.clear();
172 ScGlobal::Clear(); // Also calls ScDocumentPool::DeleteVersionMaps();
174 ScInterpreterContextPool::ModuleExiting();
176 DeleteCfg(); // Called from Exit()
179 void ScModule::ConfigurationChanged(utl::ConfigurationBroadcaster
* p
, ConfigurationHints eHints
)
181 if ( p
== m_pColorConfig
.get() )
183 // Test if detective objects have to be updated with new colors
184 // (if the detective colors haven't been used yet, there's nothing to update)
185 if ( ScDetectiveFunc::IsColorsInitialized() )
187 const svtools::ColorConfig
& rColors
= GetColorConfig();
189 ( ScDetectiveFunc::GetArrowColor() != rColors
.GetColorValue(svtools::CALCDETECTIVE
).nColor
||
190 ScDetectiveFunc::GetErrorColor() != rColors
.GetColorValue(svtools::CALCDETECTIVEERROR
).nColor
);
192 ( ScDetectiveFunc::GetCommentColor() != rColors
.GetColorValue(svtools::CALCNOTESBACKGROUND
).nColor
);
193 if ( bArrows
|| bComments
)
195 ScDetectiveFunc::InitializeColors(); // get the new colors
197 // update detective objects in all open documents
198 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst();
201 if ( auto pDocSh
= dynamic_cast<ScDocShell
* >(pObjSh
) )
204 ScDetectiveFunc( pDocSh
->GetDocument(), 0 ).UpdateAllArrowColors();
206 ScDetectiveFunc::UpdateAllComments( pDocSh
->GetDocument() );
208 pObjSh
= SfxObjectShell::GetNext( *pObjSh
);
213 const bool bKit
= comphelper::LibreOfficeKit::isActive();
215 //invalidate only the current view in tiled rendering mode, or all views otherwise
216 SfxViewShell
* pViewShell
= bKit
? SfxViewShell::Current() : SfxViewShell::GetFirst();
219 if (ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>(pViewShell
))
221 ScViewRenderingOptions
aViewRenderingOptions(pViewSh
->GetViewRenderingData());
222 Color
aFillColor(m_pColorConfig
->GetColorValue(svtools::DOCCOLOR
).nColor
);
223 aViewRenderingOptions
.SetDocColor(aFillColor
);
224 aViewRenderingOptions
.SetColorSchemeName(svtools::ColorConfig::GetCurrentSchemeName());
225 const bool bUnchanged(aViewRenderingOptions
== pViewSh
->GetViewRenderingData());
227 pViewSh
->SetViewRenderingData(aViewRenderingOptions
);
229 if (SfxObjectShell
* pKitCurrentObjSh
= bKit
? SfxObjectShell::Current() : nullptr)
231 ScModelObj
* pScModelObj
= comphelper::getFromUnoTunnel
<ScModelObj
>(pKitCurrentObjSh
->GetModel());
232 SfxLokHelper::notifyViewRenderState(pViewSh
, pScModelObj
);
233 // In Online, the document color is the one used for the background, contrary to
234 // Writer and Draw that use the application background color.
235 pViewSh
->libreOfficeKitViewCallback(LOK_CALLBACK_APPLICATION_BACKGROUND_COLOR
,
236 aFillColor
.AsRGBHexString().toUtf8());
239 // if nothing changed, and the hint was OnlyCurrentDocumentColorScheme we can skip invalidate
240 const bool bSkipInvalidate
= bUnchanged
&& eHints
== ConfigurationHints::OnlyCurrentDocumentColorScheme
;
241 if (!bSkipInvalidate
)
243 pViewSh
->PaintGrid();
245 pViewSh
->PaintLeft();
246 pViewSh
->PaintExtras();
249 ScInputHandler
* pHdl
= pViewSh
->GetInputHandler();
251 pHdl
->ForgetLastPattern(); // EditEngine BackgroundColor may change
253 else if ( dynamic_cast<const ScPreviewShell
*>( pViewShell
) != nullptr )
255 vcl::Window
* pWin
= pViewShell
->GetWindow();
261 pViewShell
= SfxViewShell::GetNext( *pViewShell
);
264 else if ( p
== m_pCTLOptions
.get() )
266 // for all documents: set digit language for printer, recalc output factor, update row heights
267 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst();
270 if ( auto pDocSh
= dynamic_cast<ScDocShell
*>(pObjSh
) )
272 OutputDevice
* pPrinter
= pDocSh
->GetPrinter();
274 pPrinter
->SetDigitLanguage( GetOptDigitLanguage() );
276 pDocSh
->CalcOutputFactor();
278 SCTAB nTabCount
= pDocSh
->GetDocument().GetTableCount();
279 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
280 pDocSh
->AdjustRowHeight( 0, pDocSh
->GetDocument().MaxRow(), nTab
);
282 pObjSh
= SfxObjectShell::GetNext( *pObjSh
);
285 // for all views (table and preview): update digit language
286 SfxViewShell
* pSh
= SfxViewShell::GetFirst();
289 if (ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>(pSh
))
291 // set ref-device for EditEngine (re-evaluates digit settings)
292 ScInputHandler
* pHdl
= GetInputHdl(pViewSh
);
294 pHdl
->UpdateRefDevice();
296 pViewSh
->DigitLanguageChanged();
297 pViewSh
->PaintGrid();
299 else if (ScPreviewShell
* pPreviewSh
= dynamic_cast<ScPreviewShell
*>(pSh
))
301 ScPreview
* pPreview
= pPreviewSh
->GetPreview();
303 pPreview
->GetOutDev()->SetDigitLanguage( GetOptDigitLanguage() );
304 pPreview
->Invalidate();
307 pSh
= SfxViewShell::GetNext( *pSh
);
312 void ScModule::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
314 if ( rHint
.GetId() == SfxHintId::Deinitializing
)
316 // ConfigItems must be removed before ConfigManager
321 void ScModule::DeleteCfg()
323 m_pViewCfg
.reset(); // Saving happens automatically before Exit()
326 m_pDefaultsCfg
.reset();
327 m_pFormulaCfg
.reset();
330 m_pNavipiCfg
.reset();
333 if ( m_pColorConfig
)
335 m_pColorConfig
->RemoveListener(this);
336 m_pColorConfig
.reset();
340 m_pCTLOptions
->RemoveListener(this);
341 m_pCTLOptions
.reset();
343 m_pUserOptions
.reset();
346 // Moved here from the App
348 void ScModule::Execute( SfxRequest
& rReq
)
350 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
351 SfxBindings
* pBindings
= pViewFrm
? &pViewFrm
->GetBindings() : nullptr;
353 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
354 sal_uInt16 nSlot
= rReq
.GetSlot();
358 case SID_CHOOSE_DESIGN
:
359 SfxApplication::CallAppBasic( u
"Template.Samples.ShowStyles"_ustr
);
361 case SID_EURO_CONVERTER
:
362 SfxApplication::CallAppBasic( u
"Euro.ConvertRun.Main"_ustr
);
364 case SID_AUTOSPELL_CHECK
:
367 const SfxPoolItem
* pItem
;
368 if (pReqArgs
&& SfxItemState::SET
== pReqArgs
->GetItemState( FN_PARAM_1
, true, &pItem
))
369 bSet
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
370 else if ( pReqArgs
&& SfxItemState::SET
== pReqArgs
->GetItemState( nSlot
, true, &pItem
) )
371 bSet
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
374 ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>(SfxViewShell::Current());
376 bSet
= !pViewSh
->IsAutoSpell();
378 bSet
= !ScModule::GetAutoSpellProperty();
381 SfxItemSetFixed
<SID_AUTOSPELL_CHECK
, SID_AUTOSPELL_CHECK
> aSet( GetPool() );
382 aSet
.Put( SfxBoolItem( SID_AUTOSPELL_CHECK
, bSet
) );
383 ModifyOptions( aSet
);
388 case SID_ATTR_METRIC
:
390 const SfxPoolItem
* pItem
;
391 if ( pReqArgs
&& SfxItemState::SET
== pReqArgs
->GetItemState( nSlot
, true, &pItem
) )
393 FieldUnit eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
396 case FieldUnit::MM
: // Just the units that are also in the dialog
398 case FieldUnit::INCH
:
399 case FieldUnit::PICA
:
400 case FieldUnit::POINT
:
403 ScAppOptions
aNewOpts( GetAppOptions() );
404 aNewOpts
.SetAppMetric( eUnit
);
405 SetAppOptions( aNewOpts
);
411 // added to avoid warnings
418 case FID_AUTOCOMPLETE
:
420 ScAppOptions
aNewOpts( GetAppOptions() );
421 bool bNew
= !aNewOpts
.GetAutoComplete();
422 aNewOpts
.SetAutoComplete( bNew
);
423 SetAppOptions( aNewOpts
);
425 pBindings
->Invalidate( FID_AUTOCOMPLETE
);
430 case SID_DETECTIVE_AUTO
:
432 ScAppOptions
aNewOpts( GetAppOptions() );
433 bool bNew
= !aNewOpts
.GetDetectiveAuto();
434 const SfxBoolItem
* pAuto
= rReq
.GetArg
<SfxBoolItem
>(SID_DETECTIVE_AUTO
);
436 bNew
= pAuto
->GetValue();
438 aNewOpts
.SetDetectiveAuto( bNew
);
439 SetAppOptions( aNewOpts
);
441 pBindings
->Invalidate( SID_DETECTIVE_AUTO
);
442 rReq
.AppendItem( SfxBoolItem( SID_DETECTIVE_AUTO
, bNew
) );
447 case SID_PSZ_FUNCTION
:
450 const SfxUInt32Item
& rItem
= pReqArgs
->Get(SID_PSZ_FUNCTION
);
452 ScAppOptions
aNewOpts( GetAppOptions() );
453 aNewOpts
.SetStatusFunc( rItem
.GetValue() );
454 SetAppOptions( aNewOpts
);
458 pBindings
->Invalidate( SID_TABLE_CELL
);
459 pBindings
->Update( SID_TABLE_CELL
); // Immediately
461 pBindings
->Invalidate( SID_PSZ_FUNCTION
);
462 pBindings
->Update( SID_PSZ_FUNCTION
);
463 // If the menu is opened again immediately
468 case SID_ATTR_LANGUAGE
:
469 case SID_ATTR_CHAR_CJK_LANGUAGE
:
470 case SID_ATTR_CHAR_CTL_LANGUAGE
:
472 const SfxPoolItem
* pItem
;
473 if ( pReqArgs
&& SfxItemState::SET
== pReqArgs
->GetItemState( GetPool().GetWhichIDFromSlotID(nSlot
), true, &pItem
) )
475 ScDocShell
* pDocSh
= dynamic_cast<ScDocShell
*>( SfxObjectShell::Current() );
478 ScDocument
& rDoc
= pDocSh
->GetDocument();
479 LanguageType eNewLang
= static_cast<const SvxLanguageItem
*>(pItem
)->GetLanguage();
480 LanguageType eLatin
, eCjk
, eCtl
;
481 rDoc
.GetLanguage( eLatin
, eCjk
, eCtl
);
482 LanguageType eOld
= ( nSlot
== SID_ATTR_CHAR_CJK_LANGUAGE
) ? eCjk
:
483 ( ( nSlot
== SID_ATTR_CHAR_CTL_LANGUAGE
) ? eCtl
: eLatin
);
484 if ( eNewLang
!= eOld
)
486 if ( nSlot
== SID_ATTR_CHAR_CJK_LANGUAGE
)
488 else if ( nSlot
== SID_ATTR_CHAR_CTL_LANGUAGE
)
493 rDoc
.SetLanguage( eLatin
, eCjk
, eCtl
);
495 ScInputHandler
* pInputHandler
= GetInputHdl();
497 pInputHandler
->UpdateSpellSettings(); // EditEngine flags
498 ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
500 pViewSh
->UpdateDrawTextOutliner(); // EditEngine flags
502 pDocSh
->SetDocumentModified();
509 case FID_FOCUS_POSWND
:
511 ScInputHandler
* pHdl
= GetInputHdl();
514 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
516 pWin
->PosGrabFocus();
522 case SID_OPEN_XML_FILTERSETTINGS
:
526 css::uno::Reference
< css::ui::dialogs::XExecutableDialog
> xDialog
= css::ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext());
527 (void)xDialog
->execute();
529 catch( css::uno::RuntimeException
& )
531 DBG_UNHANDLED_EXCEPTION("sc.ui");
537 OSL_FAIL( "ScApplication: Unknown Message." );
542 void ScModule::GetState( SfxItemSet
& rSet
)
544 ScDocShell
* pDocSh
= dynamic_cast<ScDocShell
*>( SfxObjectShell::Current() );
545 ScTabViewShell
* pTabViewShell
= pDocSh
? pDocSh
->GetBestViewShell() : nullptr;
547 SfxWhichIter
aIter(rSet
);
548 for (sal_uInt16 nWhich
= aIter
.FirstWhich(); nWhich
; nWhich
= aIter
.NextWhich())
552 // Not in the normal calc view shell (most likely in preview shell). Disable all actions.
553 rSet
.DisableItem(nWhich
);
559 case FID_AUTOCOMPLETE
:
560 rSet
.Put( SfxBoolItem( nWhich
, GetAppOptions().GetAutoComplete() ) );
562 case SID_DETECTIVE_AUTO
:
563 rSet
.Put( SfxBoolItem( nWhich
, GetAppOptions().GetDetectiveAuto() ) );
565 case SID_PSZ_FUNCTION
:
566 rSet
.Put( SfxUInt32Item( nWhich
, GetAppOptions().GetStatusFunc() ) );
568 case SID_ATTR_METRIC
:
569 rSet
.Put( SfxUInt16Item( nWhich
, sal::static_int_cast
<sal_uInt16
>(GetAppOptions().GetAppMetric()) ) );
571 case SID_AUTOSPELL_CHECK
:
572 rSet
.Put( SfxBoolItem( nWhich
, pTabViewShell
->IsAutoSpell()) );
574 case SID_ATTR_LANGUAGE
:
575 case ATTR_CJK_FONT_LANGUAGE
: // WID for SID_ATTR_CHAR_CJK_LANGUAGE
576 case ATTR_CTL_FONT_LANGUAGE
: // WID for SID_ATTR_CHAR_CTL_LANGUAGE
578 LanguageType eLatin
, eCjk
, eCtl
;
579 pDocSh
->GetDocument().GetLanguage( eLatin
, eCjk
, eCtl
);
580 LanguageType eLang
= ( nWhich
== ATTR_CJK_FONT_LANGUAGE
) ? eCjk
:
581 ( ( nWhich
== ATTR_CTL_FONT_LANGUAGE
) ? eCtl
: eLatin
);
582 rSet
.Put( SvxLanguageItem( eLang
, nWhich
) );
589 void ScModule::HideDisabledSlots( SfxItemSet
& rSet
)
591 if( SfxViewFrame
* pViewFrm
= SfxViewFrame::Current() )
593 SfxBindings
& rBindings
= pViewFrm
->GetBindings();
594 SfxWhichIter
aIter( rSet
);
595 for( sal_uInt16 nWhich
= aIter
.FirstWhich(); nWhich
!= 0; nWhich
= aIter
.NextWhich() )
597 ScViewUtil::HideDisabledSlot( rSet
, rBindings
, nWhich
);
598 // always disable the slots
599 rSet
.DisableItem( nWhich
);
604 void ScModule::ResetDragObject()
606 if (comphelper::LibreOfficeKit::isActive())
608 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
610 pViewShell
->ResetDragObject();
614 m_pDragData
->pCellTransfer
= nullptr;
615 m_pDragData
->pDrawTransfer
= nullptr;
616 m_pDragData
->pJumpLocalDoc
= nullptr;
617 m_pDragData
->aLinkDoc
.clear();
618 m_pDragData
->aLinkTable
.clear();
619 m_pDragData
->aLinkArea
.clear();
620 m_pDragData
->aJumpTarget
.clear();
621 m_pDragData
->aJumpText
.clear();
625 const ScDragData
& ScModule::GetDragData() const
627 if (comphelper::LibreOfficeKit::isActive())
629 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
631 return pViewShell
->GetDragData();
637 void ScModule::SetDragObject( ScTransferObj
* pCellObj
, ScDrawTransferObj
* pDrawObj
)
639 if (comphelper::LibreOfficeKit::isActive())
641 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
643 pViewShell
->SetDragObject(pCellObj
, pDrawObj
);
648 m_pDragData
->pCellTransfer
= pCellObj
;
649 m_pDragData
->pDrawTransfer
= pDrawObj
;
653 void ScModule::SetDragLink(
654 const OUString
& rDoc
, const OUString
& rTab
, const OUString
& rArea
)
656 if (comphelper::LibreOfficeKit::isActive())
658 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
660 pViewShell
->SetDragLink(rDoc
, rTab
, rArea
);
665 m_pDragData
->aLinkDoc
= rDoc
;
666 m_pDragData
->aLinkTable
= rTab
;
667 m_pDragData
->aLinkArea
= rArea
;
671 void ScModule::SetDragJump(
672 ScDocument
* pLocalDoc
, const OUString
& rTarget
, const OUString
& rText
)
674 if (comphelper::LibreOfficeKit::isActive())
676 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
678 pViewShell
->SetDragJump(pLocalDoc
, rTarget
, rText
);
684 m_pDragData
->pJumpLocalDoc
= pLocalDoc
;
685 m_pDragData
->aJumpTarget
= rTarget
;
686 m_pDragData
->aJumpText
= rText
;
690 ScDocument
* ScModule::GetClipDoc()
692 // called from document
693 SfxViewFrame
* pViewFrame
= nullptr;
694 ScTabViewShell
* pViewShell
= nullptr;
695 css::uno::Reference
<css::datatransfer::XTransferable2
> xTransferable
;
697 if ((pViewShell
= dynamic_cast<ScTabViewShell
*>(SfxViewShell::Current())))
698 xTransferable
.set(ScTabViewShell::GetClipData(pViewShell
->GetViewData().GetActiveWin()));
699 else if ((pViewShell
= dynamic_cast<ScTabViewShell
*>(SfxViewShell::GetFirst())))
700 xTransferable
.set(ScTabViewShell::GetClipData(pViewShell
->GetViewData().GetActiveWin()));
701 else if ((pViewFrame
= SfxViewFrame::GetFirst()))
703 css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> xClipboard
=
704 pViewFrame
->GetWindow().GetClipboard();
705 xTransferable
.set(xClipboard
.is() ? xClipboard
->getContents() : nullptr, css::uno::UNO_QUERY
);
708 const ScTransferObj
* pObj
= ScTransferObj::GetOwnClipboard(xTransferable
);
711 ScDocument
* pDoc
= pObj
->GetDocument();
712 assert((!pDoc
|| pDoc
->IsClipboard()) && "Document is not clipboard, how can that be?");
719 void ScModule::SetSelectionTransfer( ScSelectionTransferObj
* pNew
)
721 m_pSelTransfer
= pNew
;
724 void ScModule::SetViewOptions( const ScViewOptions
& rOpt
)
727 m_pViewCfg
.reset(new ScViewCfg
);
729 m_pViewCfg
->SetOptions( rOpt
);
732 const ScViewOptions
& ScModule::GetViewOptions()
735 m_pViewCfg
.reset( new ScViewCfg
);
740 void ScModule::SetDocOptions( const ScDocOptions
& rOpt
)
743 m_pDocCfg
.reset( new ScDocCfg
);
745 m_pDocCfg
->SetOptions( rOpt
);
748 const ScDocOptions
& ScModule::GetDocOptions()
751 m_pDocCfg
.reset( new ScDocCfg
);
756 void ScModule::InsertEntryToLRUList(sal_uInt16 nFIndex
)
761 const ScAppOptions
& rAppOpt
= GetAppOptions();
762 sal_uInt16 nLRUFuncCount
= std::min( rAppOpt
.GetLRUFuncListCount(), sal_uInt16(LRU_MAX
) );
763 sal_uInt16
* pLRUListIds
= rAppOpt
.GetLRUFuncList();
765 sal_uInt16 aIdxList
[LRU_MAX
];
769 while ((n
< LRU_MAX
) && n
<nLRUFuncCount
) // Iterate through old list
771 if (!bFound
&& (pLRUListIds
[n
]== nFIndex
))
772 bFound
= true; // First hit!
774 aIdxList
[n
] = pLRUListIds
[n
]; // Copy after hit
775 else if ((n
+1) < LRU_MAX
)
776 aIdxList
[n
+1] = pLRUListIds
[n
]; // Move before hit
779 if (!bFound
&& (n
< LRU_MAX
)) // Entry not found?
781 aIdxList
[0] = nFIndex
; // Current on Top
783 ScAppOptions
aNewOpts(rAppOpt
); // Let App know
784 aNewOpts
.SetLRUFuncList(aIdxList
, n
);
785 SetAppOptions(aNewOpts
);
788 void ScModule::SetAppOptions( const ScAppOptions
& rOpt
)
791 m_pAppCfg
.reset( new ScAppCfg
);
793 m_pAppCfg
->SetOptions( rOpt
);
796 void global_InitAppOptions()
798 ScModule::get()->GetAppOptions();
801 const ScAppOptions
& ScModule::GetAppOptions()
804 m_pAppCfg
.reset( new ScAppCfg
);
806 return m_pAppCfg
->GetOptions();
809 void ScModule::SetDefaultsOptions( const ScDefaultsOptions
& rOpt
)
811 if ( !m_pDefaultsCfg
)
812 m_pDefaultsCfg
.reset( new ScDefaultsCfg
);
814 m_pDefaultsCfg
->SetOptions( rOpt
);
817 const ScDefaultsOptions
& ScModule::GetDefaultsOptions()
819 if ( !m_pDefaultsCfg
)
820 m_pDefaultsCfg
.reset( new ScDefaultsCfg
);
822 return *m_pDefaultsCfg
;
825 void ScModule::SetFormulaOptions( const ScFormulaOptions
& rOpt
)
827 if ( !m_pFormulaCfg
)
828 m_pFormulaCfg
.reset( new ScFormulaCfg
);
830 m_pFormulaCfg
->SetOptions( rOpt
);
833 const ScFormulaOptions
& ScModule::GetFormulaOptions()
835 if ( !m_pFormulaCfg
)
836 m_pFormulaCfg
.reset( new ScFormulaCfg
);
838 return *m_pFormulaCfg
;
841 void ScModule::SetInputOptions( const ScInputOptions
& rOpt
)
844 m_pInputCfg
.reset( new ScInputCfg
);
846 m_pInputCfg
->SetOptions( rOpt
);
849 const ScInputOptions
& ScModule::GetInputOptions()
852 m_pInputCfg
.reset( new ScInputCfg
);
854 return m_pInputCfg
->GetOptions();
857 void ScModule::SetPrintOptions( const ScPrintOptions
& rOpt
)
860 m_pPrintCfg
.reset( new ScPrintCfg
);
862 m_pPrintCfg
->SetOptions( rOpt
);
865 const ScPrintOptions
& ScModule::GetPrintOptions()
868 m_pPrintCfg
.reset( new ScPrintCfg
);
870 return m_pPrintCfg
->GetOptions();
873 ScNavipiCfg
& ScModule::GetNavipiCfg()
876 m_pNavipiCfg
.reset( new ScNavipiCfg
);
878 return *m_pNavipiCfg
;
881 ScAddInCfg
& ScModule::GetAddInCfg()
884 m_pAddInCfg
.reset( new ScAddInCfg
);
889 svtools::ColorConfig
& ScModule::GetColorConfig()
891 if ( !m_pColorConfig
)
893 m_pColorConfig
.reset( new svtools::ColorConfig
);
894 m_pColorConfig
->AddListener(this);
897 return *m_pColorConfig
;
900 bool ScModule::IsLOKViewInDarkMode()
902 SfxViewShell
* pKitSh
= comphelper::LibreOfficeKit::isActive() ? SfxViewShell::Current() : nullptr;
905 Color aDocColor
= pKitSh
->GetColorConfigColor(svtools::DOCCOLOR
);
906 if( aDocColor
.IsDark() )
912 SvtUserOptions
& ScModule::GetUserOptions()
914 if( !m_pUserOptions
)
916 m_pUserOptions
.reset( new SvtUserOptions
);
918 return *m_pUserOptions
;
921 LanguageType
ScModule::GetOptDigitLanguage()
923 SvtCTLOptions::TextNumerals eNumerals
= SvtCTLOptions::GetCTLTextNumerals();
924 return ( eNumerals
== SvtCTLOptions::NUMERALS_ARABIC
) ? LANGUAGE_ENGLISH_US
:
925 ( eNumerals
== SvtCTLOptions::NUMERALS_HINDI
) ? LANGUAGE_ARABIC_SAUDI_ARABIA
:
932 * Items from Calc options dialog and SID_AUTOSPELL_CHECK
934 void ScModule::ModifyOptions( const SfxItemSet
& rOptSet
)
936 bool bOldAutoSpell
= GetAutoSpellProperty();
937 LanguageType nOldSpellLang
, nOldCjkLang
, nOldCtlLang
;
938 GetSpellSettings( nOldSpellLang
, nOldCjkLang
, nOldCtlLang
);
942 OSL_ENSURE( m_pAppCfg
, "AppOptions not initialised :-(" );
946 OSL_ENSURE( m_pInputCfg
, "InputOptions not initialised :-(" );
948 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
949 SfxBindings
* pBindings
= pViewFrm
? &pViewFrm
->GetBindings() : nullptr;
951 ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
952 ScDocShell
* pDocSh
= dynamic_cast<ScDocShell
*>( SfxObjectShell::Current() );
953 ScDocument
* pDoc
= pDocSh
? &pDocSh
->GetDocument() : nullptr;
954 bool bRepaint
= false;
955 bool bUpdateMarks
= false;
956 bool bUpdateRefDev
= false;
957 bool bCalcAll
= false;
958 bool bSaveAppOptions
= false;
959 bool bSaveInputOptions
= false;
960 bool bCompileErrorCells
= false;
962 // SfxGetpApp()->SetOptions( rOptSet );
964 ScAppOptions aAppOptions
= m_pAppCfg
->GetOptions();
966 // No more linguistics
967 if (const SfxUInt16Item
* pItem
= rOptSet
.GetItemIfSet(SID_ATTR_METRIC
))
970 aAppOptions
.SetAppMetric( static_cast<FieldUnit
>(pItem
->GetValue()) );
971 bSaveAppOptions
= true;
974 if (const ScUserListItem
* pItem
= rOptSet
.GetItemIfSet(SCITEM_USERLIST
))
976 ScGlobal::SetUserList( pItem
->GetUserList() );
977 bSaveAppOptions
= true;
980 if (const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_OPT_SYNCZOOM
))
982 aAppOptions
.SetSynchronizeZoom( pItem
->GetValue() );
983 bSaveAppOptions
= true;
986 if (const SfxUInt16Item
* pItem
= rOptSet
.GetItemIfSet(SID_SC_OPT_KEY_BINDING_COMPAT
))
988 sal_uInt16 nVal
= pItem
->GetValue();
989 ScOptionsUtil::KeyBindingType eOld
= aAppOptions
.GetKeyBindingType();
990 ScOptionsUtil::KeyBindingType eNew
= static_cast<ScOptionsUtil::KeyBindingType
>(nVal
);
993 aAppOptions
.SetKeyBindingType(eNew
);
994 bSaveAppOptions
= true;
995 ScDocShell::ResetKeyBindings(eNew
);
999 if (const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_OPT_LINKS
))
1001 aAppOptions
.SetLinksInsertedLikeMSExcel(pItem
->GetValue());
1002 bSaveAppOptions
= true;
1006 if (const ScTpDefaultsItem
* pItem
= rOptSet
.GetItemIfSet(SID_SCDEFAULTSOPTIONS
))
1008 const ScDefaultsOptions
& rOpt
= pItem
->GetDefaultsOptions();
1009 SetDefaultsOptions( rOpt
);
1013 if (const ScTpFormulaItem
* pItem
= rOptSet
.GetItemIfSet(SID_SCFORMULAOPTIONS
))
1015 const ScFormulaOptions
& rOpt
= pItem
->GetFormulaOptions();
1017 if (!m_pFormulaCfg
|| (*m_pFormulaCfg
!= rOpt
))
1018 // Formula options have changed. Repaint the column headers.
1021 if (m_pFormulaCfg
&& m_pFormulaCfg
->GetUseEnglishFuncName() != rOpt
.GetUseEnglishFuncName())
1023 // Re-compile formula cells with error as the error may have been
1024 // caused by unresolved function names.
1025 bCompileErrorCells
= true;
1028 // Recalc for interpreter options changes.
1029 if (m_pFormulaCfg
&& m_pFormulaCfg
->GetCalcConfig() != rOpt
.GetCalcConfig())
1034 pDocSh
->SetFormulaOptions( rOpt
);
1035 pDocSh
->SetDocumentModified();
1038 // ScDocShell::SetFormulaOptions() may check for changed settings, so
1039 // set the new options here after that has been called.
1040 if (!bCalcAll
|| rOpt
.GetWriteCalcConfig())
1042 // CalcConfig is new, didn't change or is global, simply set all.
1043 SetFormulaOptions( rOpt
);
1047 // If "only for current document" was checked, reset those affected
1048 // by that setting to previous values.
1049 ScFormulaOptions
aNewOpt( rOpt
);
1050 aNewOpt
.GetCalcConfig().MergeDocumentSpecific( m_pFormulaCfg
->GetCalcConfig());
1051 SetFormulaOptions( aNewOpt
);
1056 if (const ScTpViewItem
* pItem
= rOptSet
.GetItemIfSet(SID_SCVIEWOPTIONS
))
1058 const ScViewOptions
& rNewOpt
= pItem
->GetViewOptions();
1062 ScViewData
& rViewData
= pViewSh
->GetViewData();
1063 const ScViewOptions
& rOldOpt
= rViewData
.GetOptions();
1065 bool bAnchorList
= ( rOldOpt
.GetOption( VOPT_ANCHOR
) !=
1066 rNewOpt
.GetOption( VOPT_ANCHOR
) );
1068 if ( rOldOpt
!= rNewOpt
)
1070 rViewData
.SetOptions( rNewOpt
); // Changes rOldOpt
1071 rViewData
.GetDocument().SetViewOptions( rNewOpt
);
1073 pDocSh
->SetDocumentModified();
1077 pViewSh
->UpdateAnchorHandles();
1079 SetViewOptions( rNewOpt
);
1082 pBindings
->Invalidate(SID_HELPLINES_MOVE
);
1087 // Evaluate after ViewOptions, as GridOptions is a member of ViewOptions
1088 if ( const SvxGridItem
* pItem
= rOptSet
.GetItemIfSet(SID_ATTR_GRID_OPTIONS
) )
1090 ScGridOptions
aNewGridOpt( *pItem
);
1094 ScViewData
& rViewData
= pViewSh
->GetViewData();
1095 ScViewOptions
aNewViewOpt( rViewData
.GetOptions() );
1096 const ScGridOptions
& rOldGridOpt
= aNewViewOpt
.GetGridOptions();
1098 if ( rOldGridOpt
!= aNewGridOpt
)
1100 aNewViewOpt
.SetGridOptions( aNewGridOpt
);
1101 rViewData
.SetOptions( aNewViewOpt
);
1102 rViewData
.GetDocument().SetViewOptions( aNewViewOpt
);
1104 pDocSh
->SetDocumentModified();
1108 ScViewOptions
aNewViewOpt ( GetViewOptions() );
1109 aNewViewOpt
.SetGridOptions( aNewGridOpt
);
1110 SetViewOptions( aNewViewOpt
);
1113 pBindings
->Invalidate(SID_GRID_VISIBLE
);
1114 pBindings
->Invalidate(SID_GRID_USE
);
1119 if ( const ScTpCalcItem
* pItem
= rOptSet
.GetItemIfSet(SID_SCDOCOPTIONS
) )
1121 const ScDocOptions
& rNewOpt
= pItem
->GetDocOptions();
1125 const ScDocOptions
& rOldOpt
= pDoc
->GetDocOptions();
1127 bRepaint
= ( bRepaint
|| ( rOldOpt
!= rNewOpt
) );
1128 bCalcAll
= bRepaint
&&
1129 ( rOldOpt
.IsIter() != rNewOpt
.IsIter()
1130 || rOldOpt
.GetIterCount() != rNewOpt
.GetIterCount()
1131 || rOldOpt
.GetIterEps() != rNewOpt
.GetIterEps()
1132 || rOldOpt
.IsIgnoreCase() != rNewOpt
.IsIgnoreCase()
1133 || rOldOpt
.IsCalcAsShown() != rNewOpt
.IsCalcAsShown()
1134 || (rNewOpt
.IsCalcAsShown() &&
1135 rOldOpt
.GetStdPrecision() != rNewOpt
.GetStdPrecision())
1136 || rOldOpt
.IsMatchWholeCell() != rNewOpt
.IsMatchWholeCell()
1137 || rOldOpt
.GetYear2000() != rNewOpt
.GetYear2000()
1138 || rOldOpt
.IsFormulaRegexEnabled() != rNewOpt
.IsFormulaRegexEnabled()
1139 || rOldOpt
.IsFormulaWildcardsEnabled() != rNewOpt
.IsFormulaWildcardsEnabled()
1141 pDoc
->SetDocOptions( rNewOpt
);
1142 pDocSh
->SetDocumentModified();
1144 SetDocOptions( rNewOpt
);
1147 // Set TabDistance after the actual DocOptions
1148 if ( const SfxUInt16Item
* pItem
= rOptSet
.GetItemIfSet(SID_ATTR_DEFTABSTOP
) )
1150 sal_uInt16 nTabDist
= pItem
->GetValue();
1151 ScDocOptions
aOpt(GetDocOptions());
1152 aOpt
.SetTabDistance(nTabDist
);
1153 SetDocOptions( aOpt
);
1157 ScDocOptions
aDocOpt(pDoc
->GetDocOptions());
1158 aDocOpt
.SetTabDistance(nTabDist
);
1159 pDoc
->SetDocOptions( aDocOpt
);
1160 pDocSh
->SetDocumentModified();
1161 if(pDoc
->GetDrawLayer())
1162 pDoc
->GetDrawLayer()->SetDefaultTabulator(nTabDist
);
1166 // AutoSpell after the DocOptions (due to being a member)
1167 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_AUTOSPELL_CHECK
) ) // At DocOptions
1169 bool bDoAutoSpell
= pItem
->GetValue();
1173 if (pViewSh
->IsAutoSpell() != bDoAutoSpell
)
1175 pViewSh
->EnableAutoSpell(bDoAutoSpell
);
1177 bRepaint
= true; // Because HideAutoSpell might be invalid
1178 //TODO: Paint all Views?
1182 if ( bOldAutoSpell
!= bDoAutoSpell
)
1183 SetAutoSpellProperty( bDoAutoSpell
);
1185 pDocSh
->PostPaintGridAll(); // Due to marks
1186 ScInputHandler
* pInputHandler
= GetInputHdl();
1187 if ( pInputHandler
)
1188 pInputHandler
->UpdateSpellSettings(); // EditEngine flags
1190 pViewSh
->UpdateDrawTextOutliner(); // EditEngine flags
1193 pBindings
->Invalidate( SID_AUTOSPELL_CHECK
);
1197 ScInputOptions aInputOptions
= m_pInputCfg
->GetOptions();
1198 if ( const SfxUInt16Item
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_SELECTIONPOS
) )
1200 aInputOptions
.SetMoveDir( pItem
->GetValue() );
1201 bSaveInputOptions
= true;
1203 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_SELECTION
) )
1205 aInputOptions
.SetMoveSelection( pItem
->GetValue() );
1206 bSaveInputOptions
= true;
1208 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_EDITMODE
) )
1210 aInputOptions
.SetEnterEdit( pItem
->GetValue() );
1211 bSaveInputOptions
= true;
1213 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_FMT_EXPAND
) )
1215 aInputOptions
.SetExtendFormat( pItem
->GetValue() );
1216 bSaveInputOptions
= true;
1218 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_RANGEFINDER
) )
1220 aInputOptions
.SetRangeFinder( pItem
->GetValue() );
1221 bSaveInputOptions
= true;
1223 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_REF_EXPAND
) )
1225 aInputOptions
.SetExpandRefs( pItem
->GetValue() );
1226 bSaveInputOptions
= true;
1228 if (const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_OPT_SORT_REF_UPDATE
))
1230 aInputOptions
.SetSortRefUpdate( pItem
->GetValue());
1231 bSaveInputOptions
= true;
1234 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_MARK_HEADER
) )
1236 aInputOptions
.SetMarkHeader( pItem
->GetValue() );
1237 bSaveInputOptions
= true;
1238 bUpdateMarks
= true;
1240 if ( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet(SID_SC_INPUT_TEXTWYSIWYG
) )
1242 bool bNew
= pItem
->GetValue();
1243 if ( bNew
!= aInputOptions
.GetTextWysiwyg() )
1245 aInputOptions
.SetTextWysiwyg( bNew
);
1246 bSaveInputOptions
= true;
1247 bUpdateRefDev
= true;
1250 if( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet( SID_SC_INPUT_REPLCELLSWARN
) )
1252 aInputOptions
.SetReplaceCellsWarn( pItem
->GetValue() );
1253 bSaveInputOptions
= true;
1256 if( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet( SID_SC_INPUT_LEGACY_CELL_SELECTION
) )
1258 aInputOptions
.SetLegacyCellSelection( pItem
->GetValue() );
1259 bSaveInputOptions
= true;
1262 if( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet( SID_SC_INPUT_ENTER_PASTE_MODE
) )
1264 aInputOptions
.SetEnterPasteMode( pItem
->GetValue() );
1265 bSaveInputOptions
= true;
1268 if( const SfxBoolItem
* pItem
= rOptSet
.GetItemIfSet( SID_SC_INPUT_WARNACTIVESHEET
) )
1270 aInputOptions
.SetWarnActiveSheet( pItem
->GetValue() );
1271 bSaveInputOptions
= true;
1275 if ( const ScTpPrintItem
* pItem
= rOptSet
.GetItemIfSet(SID_SCPRINTOPTIONS
) )
1277 const ScPrintOptions
& rNewOpt
= pItem
->GetPrintOptions();
1278 SetPrintOptions( rNewOpt
);
1280 // broadcast causes all previews to recalc page numbers
1281 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScPrintOptions
) );
1284 if ( bSaveAppOptions
)
1285 m_pAppCfg
->SetOptions(aAppOptions
);
1287 if ( bSaveInputOptions
)
1288 m_pInputCfg
->SetOptions(aInputOptions
);
1290 // Kick off recalculation?
1291 if (pDoc
&& bCompileErrorCells
)
1293 // Re-compile cells with name error, and recalc if at least one cell
1294 // has been re-compiled. In the future we may want to find a way to
1295 // recalc only those that are affected.
1296 if (pDoc
->CompileErrorCells(FormulaError::NoName
))
1300 if ( pDoc
&& bCalcAll
)
1302 weld::WaitObject
aWait( ScDocShell::GetActiveDialogParent() );
1305 pViewSh
->UpdateCharts( true );
1307 ScDBFunc::DoUpdateCharts( ScAddress(), *pDoc
, true );
1309 pBindings
->Invalidate( SID_ATTR_SIZE
); //SvxPosSize StatusControl Update
1312 if ( pViewSh
&& bUpdateMarks
)
1313 pViewSh
->UpdateAutoFillMark();
1316 if ( pViewSh
&& bRepaint
)
1318 pViewSh
->UpdateFixPos();
1319 pViewSh
->PaintGrid();
1320 pViewSh
->PaintTop();
1321 pViewSh
->PaintLeft();
1322 pViewSh
->PaintExtras();
1323 pViewSh
->InvalidateBorder();
1326 pBindings
->Invalidate( FID_TOGGLEHEADERS
); // -> Checks in menu
1327 pBindings
->Invalidate( FID_TOGGLESYNTAX
);
1331 // update ref device (for all documents)
1332 if ( !bUpdateRefDev
)
1335 // for all documents: recalc output factor, update row heights
1336 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst();
1339 if ( auto pOneDocSh
= dynamic_cast<ScDocShell
*>(pObjSh
) )
1341 pOneDocSh
->CalcOutputFactor();
1342 SCTAB nTabCount
= pOneDocSh
->GetDocument().GetTableCount();
1343 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
1344 pOneDocSh
->AdjustRowHeight( 0, pDocSh
->GetDocument().MaxRow(), nTab
);
1346 pObjSh
= SfxObjectShell::GetNext( *pObjSh
);
1349 // for all (tab-) views:
1350 SfxViewShell
* pSh
= SfxViewShell::GetFirst( true, checkSfxViewShell
<ScTabViewShell
> );
1353 ScTabViewShell
* pOneViewSh
= static_cast<ScTabViewShell
*>(pSh
);
1355 // set ref-device for EditEngine
1356 ScInputHandler
* pHdl
= GetInputHdl(pOneViewSh
);
1358 pHdl
->UpdateRefDevice();
1360 // update view scale
1361 ScViewData
& rViewData
= pOneViewSh
->GetViewData();
1362 pOneViewSh
->SetZoom( rViewData
.GetZoomX(), rViewData
.GetZoomY(), false );
1365 pOneViewSh
->PaintGrid();
1366 pOneViewSh
->PaintTop();
1367 pOneViewSh
->PaintLeft();
1369 pSh
= SfxViewShell::GetNext( *pSh
, true, checkSfxViewShell
<ScTabViewShell
> );
1376 ScInputHandler
* ScModule::GetInputHdl( ScTabViewShell
* pViewSh
, bool bUseRef
)
1378 if ( !comphelper::LibreOfficeKit::isActive() && m_pRefInputHandler
&& bUseRef
)
1379 return m_pRefInputHandler
;
1381 ScInputHandler
* pHdl
= nullptr;
1384 // in case a UIActive embedded object has no ViewShell (UNO component)
1385 // the own calc view shell will be set as current, but no handling should happen
1386 ScTabViewShell
* pCurViewSh
= dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
1387 if ( pCurViewSh
&& !pCurViewSh
->GetUIActiveClient() )
1388 pViewSh
= pCurViewSh
;
1392 pHdl
= pViewSh
->GetInputHandler(); // Viewshell always has one, from now on
1394 // If no ViewShell passed or active, we can get NULL
1395 OSL_ENSURE( pHdl
|| !pViewSh
, "GetInputHdl: no InputHandler found!" );
1399 void ScModule::ViewShellChanged(bool bStopEditing
/*=true*/)
1401 ScInputHandler
* pHdl
= GetInputHdl();
1402 ScTabViewShell
* pShell
= ScTabViewShell::GetActiveViewShell();
1403 if ( pShell
&& pHdl
)
1404 pShell
->UpdateInputHandler(false, bStopEditing
);
1407 void ScModule::SetInputMode( ScInputMode eMode
, const OUString
* pInitText
)
1409 ScInputHandler
* pHdl
= GetInputHdl();
1411 pHdl
->SetMode(eMode
, pInitText
);
1414 bool ScModule::IsEditMode()
1416 ScInputHandler
* pHdl
= GetInputHdl();
1417 return pHdl
&& pHdl
->IsEditMode();
1420 bool ScModule::IsInputMode()
1422 ScInputHandler
* pHdl
= GetInputHdl();
1423 return pHdl
&& pHdl
->IsInputMode();
1426 bool ScModule::InputKeyEvent( const KeyEvent
& rKEvt
, bool bStartEdit
)
1428 ScInputHandler
* pHdl
= GetInputHdl();
1429 return pHdl
&& pHdl
->KeyInput( rKEvt
, bStartEdit
);
1432 void ScModule::InputEnterHandler( ScEnterMode nBlockMode
, bool bBeforeSavingInLOK
)
1434 if ( !SfxGetpApp()->IsDowning() ) // Not when quitting the program
1436 ScInputHandler
* pHdl
= GetInputHdl();
1438 pHdl
->EnterHandler( nBlockMode
, bBeforeSavingInLOK
);
1442 void ScModule::InputCancelHandler()
1444 ScInputHandler
* pHdl
= GetInputHdl();
1446 pHdl
->CancelHandler();
1449 void ScModule::InputSelection( const EditView
* pView
)
1451 ScInputHandler
* pHdl
= GetInputHdl();
1453 pHdl
->InputSelection( pView
);
1456 void ScModule::InputChanged( const EditView
* pView
)
1458 ScInputHandler
* pHdl
= GetInputHdl();
1460 pHdl
->InputChanged( pView
, false );
1463 void ScModule::ViewShellGone( const ScTabViewShell
* pViewSh
)
1465 ScInputHandler
* pHdl
= GetInputHdl();
1467 pHdl
->ViewShellGone( pViewSh
);
1470 void ScModule::SetRefInputHdl( ScInputHandler
* pNew
)
1472 m_pRefInputHandler
= pNew
;
1475 void ScModule::InputGetSelection( sal_Int32
& rStart
, sal_Int32
& rEnd
)
1477 ScInputHandler
* pHdl
= GetInputHdl();
1479 pHdl
->InputGetSelection( rStart
, rEnd
);
1482 void ScModule::InputSetSelection( sal_Int32 nStart
, sal_Int32 nEnd
)
1484 ScInputHandler
* pHdl
= GetInputHdl();
1486 pHdl
->InputSetSelection( nStart
, nEnd
);
1489 void ScModule::InputReplaceSelection( std::u16string_view aStr
)
1491 ScInputHandler
* pHdl
= GetInputHdl();
1493 pHdl
->InputReplaceSelection( aStr
);
1496 void ScModule::InputTurnOffWinEngine()
1498 ScInputHandler
* pHdl
= GetInputHdl();
1500 pHdl
->InputTurnOffWinEngine();
1503 void ScModule::ActivateInputWindow( const OUString
* pStrFormula
, bool bMatrix
)
1505 ScInputHandler
* pHdl
= GetInputHdl();
1509 ScInputWindow
* pWin
= pHdl
->GetInputWindow();
1512 // Take over formula
1515 pWin
->SetFuncString( *pStrFormula
, false );
1516 // SetSumAssignMode due to sal_False not necessary
1518 ScEnterMode nMode
= bMatrix
? ScEnterMode::MATRIX
: ScEnterMode::NORMAL
;
1519 pHdl
->EnterHandler( nMode
);
1521 // Without Invalidate the selection remains active, if the formula has not changed
1523 pWin
->TextInvalidate();
1530 pWin
->SetFuncString( OUString(), false );
1531 // SetSumAssignMode due to sal_False no necessary
1533 pHdl
->CancelHandler();
1540 void ScModule::SetRefDialog( sal_uInt16 nId
, bool bVis
, SfxViewFrame
* pViewFrm
)
1542 //TODO: Move reference dialog handling to view
1543 // Just keep function autopilot here for references to other documents
1544 if ( !(m_nCurRefDlgId
== 0 || ( nId
== m_nCurRefDlgId
&& !bVis
)
1545 || ( comphelper::LibreOfficeKit::isActive() )) )
1549 pViewFrm
= SfxViewFrame::Current();
1551 // bindings update causes problems with update of stylist if
1552 // current style family has changed
1554 // pViewFrm->GetBindings().Update(); // to avoid trouble in LockDispatcher
1556 // before SetChildWindow
1557 if ( comphelper::LibreOfficeKit::isActive() )
1560 m_nCurRefDlgId
= nId
;
1564 m_nCurRefDlgId
= bVis
? nId
: 0;
1569 // store the dialog id also in the view shell
1570 SfxViewShell
* pViewSh
= pViewFrm
->GetViewShell();
1571 if (ScTabViewShell
* pTabViewSh
= dynamic_cast<ScTabViewShell
*>(pViewSh
))
1572 pTabViewSh
->SetCurRefDlgId(m_nCurRefDlgId
);
1575 // no ScTabViewShell - possible for example from a Basic macro
1577 m_nCurRefDlgId
= 0; // don't set nCurRefDlgId if no dialog is created
1580 pViewFrm
->SetChildWindow( nId
, bVis
);
1583 SfxApplication
* pSfxApp
= SfxGetpApp();
1584 pSfxApp
->Broadcast( SfxHint( SfxHintId::ScRefModeChanged
) );
1587 static SfxChildWindow
* lcl_GetChildWinFromCurrentView( sal_uInt16 nId
)
1589 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
1591 // #i46999# current view frame can be null (for example, when closing help)
1592 return pViewFrm
? pViewFrm
->GetChildWindow( nId
) : nullptr;
1595 static SfxChildWindow
* lcl_GetChildWinFromAnyView( sal_uInt16 nId
)
1597 // First, try the current view
1598 SfxChildWindow
* pChildWnd
= lcl_GetChildWinFromCurrentView( nId
);
1600 return pChildWnd
; // found in the current view
1602 // if not found there, get the child window from any open view
1603 // it can be open only in one view because nCurRefDlgId is global
1605 SfxViewFrame
* pViewFrm
= SfxViewFrame::GetFirst();
1608 pChildWnd
= pViewFrm
->GetChildWindow( nId
);
1610 return pChildWnd
; // found in any view
1612 pViewFrm
= SfxViewFrame::GetNext( *pViewFrm
);
1615 return nullptr; // none found
1618 bool ScModule::IsModalMode(SfxObjectShell
* pDocSh
)
1620 //TODO: Move reference dialog handling to view
1621 // Just keep function autopilot here for references to other documents
1622 bool bIsModal
= false;
1624 if ( m_nCurRefDlgId
)
1626 SfxChildWindow
* pChildWnd
= lcl_GetChildWinFromCurrentView( m_nCurRefDlgId
);
1629 if (pChildWnd
->GetController())
1631 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1633 bIsModal
= pChildWnd
->IsVisible() && pRefDlg
&&
1634 !( pRefDlg
->IsRefInputMode() && pRefDlg
->IsDocAllowed(pDocSh
) );
1637 else if ( pDocSh
&& comphelper::LibreOfficeKit::isActive() )
1639 // m_nCurRefDlgId is not deglobalized so it can be set by other view
1640 // in LOK case when no ChildWindow for this view was detected -> fallback
1641 ScInputHandler
* pHdl
= GetInputHdl();
1643 bIsModal
= pHdl
->IsModalMode(pDocSh
);
1648 ScInputHandler
* pHdl
= GetInputHdl();
1650 bIsModal
= pHdl
->IsModalMode(pDocSh
);
1656 bool ScModule::IsTableLocked()
1658 //TODO: Move reference dialog handling to view
1659 // Just keep function autopilot here for references to other documents
1660 bool bLocked
= false;
1662 // Up until now just for ScAnyRefDlg
1663 if ( m_nCurRefDlgId
)
1665 SfxChildWindow
* pChildWnd
= lcl_GetChildWinFromAnyView( m_nCurRefDlgId
);
1668 if (pChildWnd
->GetController())
1670 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1673 bLocked
= pRefDlg
->IsTableLocked();
1676 else if (!comphelper::LibreOfficeKit::isActive())
1677 bLocked
= true; // for other views, see IsModalMode
1680 // We can't stop LOK clients from switching part, and getting out of sync.
1681 assert(!bLocked
|| !comphelper::LibreOfficeKit::isActive());
1686 bool ScModule::IsRefDialogOpen()
1688 //TODO: Move reference dialog handling to view
1689 // Just keep function autopilot here for references to other documents
1690 bool bIsOpen
= false;
1692 if ( m_nCurRefDlgId
)
1694 SfxChildWindow
* pChildWnd
= lcl_GetChildWinFromCurrentView( m_nCurRefDlgId
);
1696 bIsOpen
= pChildWnd
->IsVisible();
1702 bool ScModule::IsFormulaMode()
1704 //TODO: Move reference dialog handling to view
1705 // Just keep function autopilot here for references to other documents
1706 bool bIsFormula
= false;
1708 if ( m_nCurRefDlgId
)
1710 SfxChildWindow
* pChildWnd
= nullptr;
1712 if ( comphelper::LibreOfficeKit::isActive() )
1713 pChildWnd
= lcl_GetChildWinFromCurrentView( m_nCurRefDlgId
);
1715 pChildWnd
= lcl_GetChildWinFromAnyView( m_nCurRefDlgId
);
1719 if (pChildWnd
->GetController())
1721 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1723 bIsFormula
= pChildWnd
->IsVisible() && pRefDlg
&& pRefDlg
->IsRefInputMode();
1726 else if ( comphelper::LibreOfficeKit::isActive() )
1728 // m_nCurRefDlgId is not deglobalized so it can be set by other view
1729 // in LOK case when no ChildWindow for this view was detected -> fallback
1730 ScInputHandler
* pHdl
= GetInputHdl();
1732 bIsFormula
= pHdl
->IsFormulaMode();
1737 ScInputHandler
* pHdl
= GetInputHdl();
1739 bIsFormula
= pHdl
->IsFormulaMode();
1742 if (m_bIsInEditCommand
)
1748 static void lcl_MarkedTabs( const ScMarkData
& rMark
, SCTAB
& rStartTab
, SCTAB
& rEndTab
)
1750 if (rMark
.GetSelectCount() > 1)
1752 rEndTab
= rMark
.GetLastSelected();
1753 rStartTab
= rMark
.GetFirstSelected();
1757 void ScModule::SetReference( const ScRange
& rRef
, ScDocument
& rDoc
,
1758 const ScMarkData
* pMarkData
)
1760 //TODO: Move reference dialog handling to view
1761 // Just keep function autopilot here for references to other documents
1763 // In RefDialogs we also trigger the ZoomIn, if the Ref's Start and End are different
1764 ScRange aNew
= rRef
;
1765 aNew
.PutInOrder(); // Always in the right direction
1767 if( m_nCurRefDlgId
)
1769 SfxChildWindow
* pChildWnd
= nullptr;
1771 if ( comphelper::LibreOfficeKit::isActive() )
1772 pChildWnd
= lcl_GetChildWinFromCurrentView( m_nCurRefDlgId
);
1774 pChildWnd
= lcl_GetChildWinFromAnyView( m_nCurRefDlgId
);
1776 OSL_ENSURE( pChildWnd
, "NoChildWin" );
1779 if ( m_nCurRefDlgId
== SID_OPENDLG_CONSOLIDATE
&& pMarkData
)
1781 SCTAB nStartTab
= aNew
.aStart
.Tab();
1782 SCTAB nEndTab
= aNew
.aEnd
.Tab();
1783 lcl_MarkedTabs( *pMarkData
, nStartTab
, nEndTab
);
1784 aNew
.aStart
.SetTab(nStartTab
);
1785 aNew
.aEnd
.SetTab(nEndTab
);
1788 if (pChildWnd
->GetController())
1790 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1794 // hide the (color) selection now instead of later from LoseFocus,
1795 // don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1796 pRefDlg
->HideReference( false );
1797 pRefDlg
->SetReference( aNew
, rDoc
);
1801 else if ( comphelper::LibreOfficeKit::isActive() )
1803 // m_nCurRefDlgId is not deglobalized so it can be set by other view
1804 // in LOK case when no ChildWindow for this view was detected -> fallback
1805 ScInputHandler
* pHdl
= GetInputHdl();
1807 pHdl
->SetReference( aNew
, rDoc
);
1812 ScInputHandler
* pHdl
= GetInputHdl();
1814 pHdl
->SetReference( aNew
, rDoc
);
1817 OSL_FAIL("SetReference without receiver");
1823 * Multiple selection
1825 void ScModule::AddRefEntry()
1827 //TODO: Move reference dialog handling to view
1828 // Just keep function autopilot here for references to other documents
1829 if ( m_nCurRefDlgId
)
1831 SfxChildWindow
* pChildWnd
= lcl_GetChildWinFromAnyView( m_nCurRefDlgId
);
1832 OSL_ENSURE( pChildWnd
, "NoChildWin" );
1835 if (pChildWnd
->GetController())
1837 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1841 pRefDlg
->AddRefEntry();
1848 ScInputHandler
* pHdl
= GetInputHdl();
1850 pHdl
->AddRefEntry();
1854 void ScModule::EndReference()
1856 //TODO: Move reference dialog handling to view
1857 // Just keep function autopilot here for references to other documents
1859 // We also annul the ZoomIn again in RefDialogs
1861 //FIXME: ShowRefFrame at InputHdl, if the Function AutoPilot is open?
1862 if ( !m_nCurRefDlgId
)
1865 SfxChildWindow
* pChildWnd
= nullptr;
1867 if ( comphelper::LibreOfficeKit::isActive() )
1868 pChildWnd
= lcl_GetChildWinFromCurrentView( m_nCurRefDlgId
);
1870 pChildWnd
= lcl_GetChildWinFromAnyView( m_nCurRefDlgId
);
1872 OSL_ENSURE( pChildWnd
, "NoChildWin" );
1875 if (pChildWnd
->GetController())
1877 IAnyRefDialog
* pRefDlg
= dynamic_cast<IAnyRefDialog
*>(pChildWnd
->GetController().get());
1881 pRefDlg
->SetActive();
1888 * Idle/OnlineSpelling
1890 void ScModule::AnythingChanged()
1892 sal_uInt64 nOldTime
= m_aIdleTimer
.GetTimeout();
1893 if ( nOldTime
!= SC_IDLE_MIN
)
1894 m_aIdleTimer
.SetTimeout( SC_IDLE_MIN
);
1899 static void lcl_CheckNeedsRepaint( const ScDocShell
* pDocShell
)
1901 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocShell
);
1904 SfxViewShell
* p
= pFrame
->GetViewShell();
1905 ScTabViewShell
* pViewSh
= dynamic_cast< ScTabViewShell
*>( p
);
1907 pViewSh
->CheckNeedsRepaint();
1908 pFrame
= SfxViewFrame::GetNext( *pFrame
, pDocShell
);
1912 IMPL_LINK_NOARG(ScModule
, IdleHandler
, Timer
*, void)
1914 if ( Application::AnyInput( VclInputFlags::MOUSE
| VclInputFlags::KEYBOARD
) )
1916 m_aIdleTimer
.Start(); // Timeout unchanged
1921 ScDocShell
* pDocSh
= dynamic_cast<ScDocShell
*>(SfxObjectShell::Current());
1925 ScDocument
& rDoc
= pDocSh
->GetDocument();
1926 sc::DocumentLinkManager
& rLinkMgr
= rDoc
.GetDocLinkManager();
1927 bool bLinks
= rLinkMgr
.idleCheckLinks();
1928 bool bWidth
= rDoc
.IdleCalcTextWidth();
1930 bMore
= bLinks
|| bWidth
; // Still something at all?
1932 // While calculating a Basic formula, a paint event may have occurred,
1933 // so check the bNeedsRepaint flags for this document's views
1935 lcl_CheckNeedsRepaint( pDocSh
);
1939 sal_uInt64 nOldTime
= m_aIdleTimer
.GetTimeout();
1940 sal_uInt64 nNewTime
= nOldTime
;
1943 nNewTime
= SC_IDLE_MIN
;
1948 // Set SC_IDLE_COUNT to initial Timeout - increase afterwards
1949 if ( nIdleCount
< SC_IDLE_COUNT
)
1953 nNewTime
+= SC_IDLE_STEP
;
1954 if ( nNewTime
> SC_IDLE_MAX
)
1955 nNewTime
= SC_IDLE_MAX
;
1958 if ( nNewTime
!= nOldTime
)
1959 m_aIdleTimer
.SetTimeout( nNewTime
);
1962 m_aIdleTimer
.Start();
1966 * Virtual methods for the OptionsDialog
1968 std::optional
<SfxItemSet
> ScModule::CreateItemSet( sal_uInt16 nId
)
1970 std::optional
<SfxItemSet
> pRet
;
1971 if(SID_SC_EDITOPTIONS
== nId
)
1977 SCITEM_USERLIST
, SCITEM_USERLIST
,
1979 SID_ATTR_GRID_OPTIONS
, SID_ATTR_GRID_OPTIONS
,
1980 SID_ATTR_METRIC
, SID_ATTR_METRIC
,
1981 SID_ATTR_DEFTABSTOP
, SID_ATTR_DEFTABSTOP
,
1983 SID_SC_INPUT_LEGACY_CELL_SELECTION
, SID_SC_OPT_SORT_REF_UPDATE
,
1984 // TP_FORMULA, TP_DEFAULTS:
1985 SID_SCFORMULAOPTIONS
, SID_SCDEFAULTSOPTIONS
,
1986 // TP_VIEW, TP_CALC:
1987 SID_SCVIEWOPTIONS
, SID_SCDOCOPTIONS
,
1989 SID_SC_INPUT_WARNACTIVESHEET
, SID_SC_INPUT_ENTER_PASTE_MODE
,
1991 SID_SCPRINTOPTIONS
, SID_SCPRINTOPTIONS
,
1993 SID_SC_INPUT_SELECTION
, SID_SC_INPUT_MARK_HEADER
,
1994 SID_SC_INPUT_TEXTWYSIWYG
, SID_SC_INPUT_TEXTWYSIWYG
,
1995 SID_SC_INPUT_REPLCELLSWARN
, SID_SC_INPUT_REPLCELLSWARN
,
1997 SID_SC_OPT_SYNCZOOM
, SID_SC_OPT_KEY_BINDING_COMPAT
,
1998 SID_SC_OPT_LINKS
, SID_SC_OPT_LINKS
>);
2000 const ScAppOptions
& rAppOpt
= GetAppOptions();
2002 ScDocShell
* pDocSh
= dynamic_cast< ScDocShell
*>( SfxObjectShell::Current() );
2003 ScDocOptions aCalcOpt
= pDocSh
2004 ? pDocSh
->GetDocument().GetDocOptions()
2007 ScTabViewShell
* pViewSh
= dynamic_cast< ScTabViewShell
*>( SfxViewShell::Current() );
2008 ScViewOptions aViewOpt
= pViewSh
2009 ? pViewSh
->GetViewData().GetOptions()
2012 ScUserListItem
aULItem( SCITEM_USERLIST
);
2013 const ScUserList
& rUL
= ScGlobal::GetUserList();
2015 // SfxGetpApp()->GetOptions( aSet );
2017 pRet
->Put( SfxUInt16Item( SID_ATTR_METRIC
,
2018 sal::static_int_cast
<sal_uInt16
>(rAppOpt
.GetAppMetric()) ) );
2021 pRet
->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP
,
2022 aCalcOpt
.GetTabDistance()));
2023 pRet
->Put( ScTpCalcItem( SID_SCDOCOPTIONS
, aCalcOpt
) );
2026 pRet
->Put( ScTpViewItem( aViewOpt
) );
2027 pRet
->Put( SfxBoolItem( SID_SC_OPT_SYNCZOOM
, rAppOpt
.GetSynchronizeZoom() ) );
2030 const ScInputOptions
& rInpOpt
= GetInputOptions();
2031 pRet
->Put( SfxUInt16Item( SID_SC_INPUT_SELECTIONPOS
,
2032 rInpOpt
.GetMoveDir() ) );
2033 pRet
->Put( SfxBoolItem( SID_SC_INPUT_SELECTION
,
2034 rInpOpt
.GetMoveSelection() ) );
2035 pRet
->Put( SfxBoolItem( SID_SC_INPUT_EDITMODE
,
2036 rInpOpt
.GetEnterEdit() ) );
2037 pRet
->Put( SfxBoolItem( SID_SC_INPUT_FMT_EXPAND
,
2038 rInpOpt
.GetExtendFormat() ) );
2039 pRet
->Put( SfxBoolItem( SID_SC_INPUT_RANGEFINDER
,
2040 rInpOpt
.GetRangeFinder() ) );
2041 pRet
->Put( SfxBoolItem( SID_SC_INPUT_REF_EXPAND
,
2042 rInpOpt
.GetExpandRefs() ) );
2043 pRet
->Put( SfxBoolItem(SID_SC_OPT_SORT_REF_UPDATE
, rInpOpt
.GetSortRefUpdate()));
2044 pRet
->Put( SfxBoolItem( SID_SC_INPUT_MARK_HEADER
,
2045 rInpOpt
.GetMarkHeader() ) );
2046 pRet
->Put( SfxBoolItem( SID_SC_INPUT_TEXTWYSIWYG
,
2047 rInpOpt
.GetTextWysiwyg() ) );
2048 pRet
->Put( SfxBoolItem( SID_SC_INPUT_REPLCELLSWARN
,
2049 rInpOpt
.GetReplaceCellsWarn() ) );
2050 pRet
->Put( SfxBoolItem( SID_SC_INPUT_LEGACY_CELL_SELECTION
,
2051 rInpOpt
.GetLegacyCellSelection() ) );
2052 pRet
->Put( SfxBoolItem( SID_SC_INPUT_ENTER_PASTE_MODE
,
2053 rInpOpt
.GetEnterPasteMode() ) );
2054 pRet
->Put( SfxBoolItem( SID_SC_INPUT_WARNACTIVESHEET
,
2055 rInpOpt
.GetWarnActiveSheet() ) );
2058 pRet
->Put( ScTpPrintItem( GetPrintOptions() ) );
2061 pRet
->Put( aViewOpt
.CreateGridItem() );
2064 aULItem
.SetUserList(rUL
);
2068 pRet
->Put( SfxUInt16Item( SID_SC_OPT_KEY_BINDING_COMPAT
,
2069 rAppOpt
.GetKeyBindingType() ) );
2070 pRet
->Put( SfxBoolItem( SID_SC_OPT_LINKS
, rAppOpt
.GetLinksInsertedLikeMSExcel()));
2073 pRet
->Put( ScTpDefaultsItem( GetDefaultsOptions() ) );
2076 ScFormulaOptions aOptions
= GetFormulaOptions();
2079 ScCalcConfig
aConfig( aOptions
.GetCalcConfig());
2080 aConfig
.MergeDocumentSpecific( pDocSh
->GetDocument().GetCalcConfig());
2081 aOptions
.SetCalcConfig( aConfig
);
2083 pRet
->Put( ScTpFormulaItem( std::move(aOptions
) ) );
2088 void ScModule::ApplyItemSet( sal_uInt16 nId
, const SfxItemSet
& rSet
)
2090 if(SID_SC_EDITOPTIONS
== nId
)
2092 ModifyOptions( rSet
);
2096 std::unique_ptr
<SfxTabPage
> ScModule::CreateTabPage( sal_uInt16 nId
, weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
2098 std::unique_ptr
<SfxTabPage
> xRet
;
2099 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
2102 case SID_SC_TP_LAYOUT
:
2104 ::CreateTabPage ScTpLayoutOptionsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_LAYOUT
);
2105 if (ScTpLayoutOptionsCreate
)
2106 xRet
= (*ScTpLayoutOptionsCreate
)(pPage
, pController
, &rSet
);
2109 case SID_SC_TP_CONTENT
:
2111 ::CreateTabPage ScTpContentOptionsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_CONTENT
);
2112 if (ScTpContentOptionsCreate
)
2113 xRet
= (*ScTpContentOptionsCreate
)(pPage
, pController
, &rSet
);
2116 case SID_SC_TP_GRID
:
2117 xRet
= SvxGridTabPage::Create(pPage
, pController
, rSet
);
2119 case SID_SC_TP_USERLISTS
:
2121 ::CreateTabPage ScTpUserListsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_USERLISTS
);
2122 if (ScTpUserListsCreate
)
2123 xRet
= (*ScTpUserListsCreate
)(pPage
, pController
, &rSet
);
2126 case SID_SC_TP_CALC
:
2128 ::CreateTabPage ScTpCalcOptionsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_CALC
);
2129 if (ScTpCalcOptionsCreate
)
2130 xRet
= (*ScTpCalcOptionsCreate
)(pPage
, pController
, &rSet
);
2133 case SID_SC_TP_FORMULA
:
2135 ::CreateTabPage ScTpFormulaOptionsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_FORMULA
);
2136 if (ScTpFormulaOptionsCreate
)
2137 xRet
= (*ScTpFormulaOptionsCreate
)(pPage
, pController
, &rSet
);
2140 case SID_SC_TP_COMPATIBILITY
:
2142 ::CreateTabPage ScTpCompatOptionsCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_COMPATIBILITY
);
2143 if (ScTpCompatOptionsCreate
)
2144 xRet
= (*ScTpCompatOptionsCreate
)(pPage
, pController
, &rSet
);
2147 case SID_SC_TP_CHANGES
:
2149 ::CreateTabPage ScRedlineOptionsTabPageCreate
= pFact
->GetTabPageCreatorFunc(SID_SC_TP_CHANGES
);
2150 if (ScRedlineOptionsTabPageCreate
)
2151 xRet
=(*ScRedlineOptionsTabPageCreate
)(pPage
, pController
, &rSet
);
2154 case RID_SC_TP_PRINT
:
2156 ::CreateTabPage ScTpPrintOptionsCreate
= pFact
->GetTabPageCreatorFunc(RID_SC_TP_PRINT
);
2157 if (ScTpPrintOptionsCreate
)
2158 xRet
= (*ScTpPrintOptionsCreate
)(pPage
, pController
, &rSet
);
2161 case RID_SC_TP_DEFAULTS
:
2163 ::CreateTabPage ScTpDefaultsOptionsCreate
= pFact
->GetTabPageCreatorFunc(RID_SC_TP_DEFAULTS
);
2164 if (ScTpDefaultsOptionsCreate
)
2165 xRet
= (*ScTpDefaultsOptionsCreate
)(pPage
, pController
, &rSet
);
2170 OSL_ENSURE( xRet
, "ScModule::CreateTabPage(): no valid ID for TabPage!" );
2175 IMPL_LINK( ScModule
, CalcFieldValueHdl
, EditFieldInfo
*, pInfo
, void )
2177 //TODO: Merge with ScFieldEditEngine!
2181 const SvxFieldItem
& rField
= pInfo
->GetField();
2182 const SvxFieldData
* pField
= rField
.GetField();
2184 if (const SvxURLField
* pURLField
= dynamic_cast<const SvxURLField
*>(pField
))
2187 const OUString
& aURL
= pURLField
->GetURL();
2189 switch ( pURLField
->GetFormat() )
2191 case SvxURLFormat::AppDefault
: //TODO: Settable in the App?
2192 case SvxURLFormat::Repr
:
2194 pInfo
->SetRepresentation( pURLField
->GetRepresentation() );
2198 case SvxURLFormat::Url
:
2200 pInfo
->SetRepresentation( aURL
);
2205 svtools::ColorConfigEntry eEntry
=
2206 INetURLHistory::GetOrCreate()->QueryUrl( aURL
) ? svtools::LINKSVISITED
: svtools::LINKS
;
2207 pInfo
->SetTextColor( GetColorConfig().GetColorValue(eEntry
).nColor
);
2211 OSL_FAIL("Unknown Field");
2212 pInfo
->SetRepresentation(OUString('?'));
2216 void ScModule::RegisterRefController(sal_uInt16 nSlotId
, std::shared_ptr
<SfxDialogController
>& rWnd
, weld::Window
* pWndAncestor
)
2218 std::vector
<std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>> & rlRefWindow
= m_mapRefController
[nSlotId
];
2220 if (std::none_of(rlRefWindow
.begin(), rlRefWindow
.end(),
2221 [rWnd
](const std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>& rCandidate
)
2223 return rCandidate
.first
.get() == rWnd
.get();
2226 rlRefWindow
.emplace_back(rWnd
, pWndAncestor
);
2230 void ScModule::UnregisterRefController(sal_uInt16 nSlotId
, const std::shared_ptr
<SfxDialogController
>& rWnd
)
2232 auto iSlot
= m_mapRefController
.find( nSlotId
);
2234 if( iSlot
== m_mapRefController
.end() )
2237 std::vector
<std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>> & rlRefWindow
= iSlot
->second
;
2239 auto i
= std::find_if(rlRefWindow
.begin(), rlRefWindow
.end(),
2240 [rWnd
](const std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>& rCandidate
)
2242 return rCandidate
.first
.get() == rWnd
.get();
2245 if( i
== rlRefWindow
.end() )
2248 rlRefWindow
.erase( i
);
2250 if( rlRefWindow
.empty() )
2251 m_mapRefController
.erase( nSlotId
);
2254 std::shared_ptr
<SfxDialogController
> ScModule::Find1RefWindow(sal_uInt16 nSlotId
, const weld::Window
*pWndAncestor
)
2259 auto iSlot
= m_mapRefController
.find( nSlotId
);
2261 if( iSlot
== m_mapRefController
.end() )
2264 std::vector
<std::pair
<std::shared_ptr
<SfxDialogController
>, weld::Window
*>> & rlRefWindow
= iSlot
->second
;
2266 for (auto const& refWindow
: rlRefWindow
)
2267 if ( refWindow
.second
== pWndAncestor
)
2268 return refWindow
.first
;
2273 using namespace com::sun::star
;
2275 constexpr OUStringLiteral LINGUPROP_AUTOSPELL
= u
"IsSpellAuto";
2277 void ScModule::GetSpellSettings( LanguageType
& rDefLang
, LanguageType
& rCjkLang
, LanguageType
& rCtlLang
)
2279 // use SvtLinguConfig instead of service LinguProperties to avoid
2280 // loading the linguistic component
2281 SvtLinguConfig aConfig
;
2283 SvtLinguOptions aOptions
;
2284 aConfig
.GetOptions( aOptions
);
2286 rDefLang
= MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage
, css::i18n::ScriptType::LATIN
);
2287 rCjkLang
= MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CJK
, css::i18n::ScriptType::ASIAN
);
2288 rCtlLang
= MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CTL
, css::i18n::ScriptType::COMPLEX
);
2291 void ScModule::SetAutoSpellProperty( bool bSet
)
2293 // use SvtLinguConfig instead of service LinguProperties to avoid
2294 // loading the linguistic component
2295 SvtLinguConfig aConfig
;
2297 aConfig
.SetProperty( LINGUPROP_AUTOSPELL
, uno::Any(bSet
) );
2300 bool ScModule::GetAutoSpellProperty()
2302 // use SvtLinguConfig instead of service LinguProperties to avoid
2303 // loading the linguistic component
2304 SvtLinguConfig aConfig
;
2306 SvtLinguOptions aOptions
;
2307 aConfig
.GetOptions( aOptions
);
2309 return aOptions
.bIsSpellAuto
;
2312 bool ScModule::HasThesaurusLanguage( LanguageType nLang
)
2314 if ( nLang
== LANGUAGE_NONE
)
2317 bool bHasLang
= false;
2320 uno::Reference
< linguistic2::XThesaurus
> xThes(LinguMgr::GetThesaurus());
2322 bHasLang
= xThes
->hasLocale( LanguageTag::convertToLocale( nLang
) );
2324 catch( uno::Exception
& )
2326 OSL_FAIL("Error in Thesaurus");
2332 std::optional
<SfxStyleFamilies
> ScModule::CreateStyleFamilies()
2334 SfxStyleFamilies aStyleFamilies
;
2335 std::locale resLocale
= ScModule::get()->GetResLocale();
2337 aStyleFamilies
.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Para
,
2338 ScResId(STR_STYLE_FAMILY_CELL
),
2339 BMP_STYLES_FAMILY_CELL
,
2340 RID_CELLSTYLEFAMILY
, resLocale
));
2342 aStyleFamilies
.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Page
,
2343 ScResId(STR_STYLE_FAMILY_PAGE
),
2344 BMP_STYLES_FAMILY_PAGE
,
2345 RID_PAGESTYLEFAMILY
, resLocale
));
2347 aStyleFamilies
.emplace_back(SfxStyleFamilyItem(SfxStyleFamily::Frame
,
2348 ScResId(STR_STYLE_FAMILY_GRAPHICS
),
2349 BMP_STYLES_FAMILY_GRAPHICS
,
2350 RID_GRAPHICSTYLEFAMILY
, resLocale
));
2352 return aStyleFamilies
;
2355 void ScModule::RegisterAutomationApplicationEventsCaller(css::uno::Reference
< ooo::vba::XSinkCaller
> const& xCaller
)
2357 mxAutomationApplicationEventsCaller
= xCaller
;
2360 void ScModule::CallAutomationApplicationEventSinks(const OUString
& Method
, css::uno::Sequence
< css::uno::Any
>& Arguments
)
2362 if (mxAutomationApplicationEventsCaller
.is())
2363 mxAutomationApplicationEventsCaller
->CallSinks(Method
, Arguments
);
2366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */