fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / app / scmod.cxx
blob328785e4df3df4bdaf53396f98b28e20946dcfb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <config_features.h>
22 #include <com/sun/star/ui/dialogs/XSLTFilterDialog.hpp>
23 #include <comphelper/processfactory.hxx>
25 #include "scitems.hxx"
26 #include <sfx2/app.hxx>
27 #include <editeng/eeitem.hxx>
29 #include <editeng/flditem.hxx>
30 #include <editeng/outliner.hxx>
31 #include <basic/sbstar.hxx>
33 #include <sfx2/sfxdlg.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/objface.hxx>
37 #include "IAnyRefDialog.hxx"
38 #include "anyrefdg.hxx"
40 #include <svtools/ehdl.hxx>
41 #include <svtools/accessibilityoptions.hxx>
42 #include <svl/ctloptions.hxx>
43 #include <unotools/useroptions.hxx>
44 #include <vcl/status.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/request.hxx>
47 #include <sfx2/printer.hxx>
48 #include <editeng/langitem.hxx>
49 #include <svtools/colorcfg.hxx>
51 #include <svl/whiter.hxx>
52 #include <svx/selctrl.hxx>
53 #include <svx/insctrl.hxx>
54 #include <svx/zoomctrl.hxx>
55 #include <svx/modctrl.hxx>
56 #include <svx/pszctrl.hxx>
57 #include <svx/zoomsliderctrl.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <svl/inethist.hxx>
60 #include <vcl/waitobj.hxx>
61 #include <svx/svxerr.hxx>
62 #include <tools/diagnose_ex.h>
64 #include <editeng/unolingu.hxx>
65 #include <unotools/lingucfg.hxx>
66 #include <i18nlangtag/mslangid.hxx>
67 #include <i18nlangtag/languagetag.hxx>
68 #include <com/sun/star/i18n/ScriptType.hpp>
69 #include <com/sun/star/linguistic2/XThesaurus.hpp>
70 #include <com/sun/star/lang/Locale.hpp>
72 #include "scmod.hxx"
73 #include "global.hxx"
74 #include "viewopti.hxx"
75 #include "docoptio.hxx"
76 #include "appoptio.hxx"
77 #include "defaultsoptions.hxx"
78 #include "formulaopt.hxx"
79 #include "inputopt.hxx"
80 #include "printopt.hxx"
81 #include "navicfg.hxx"
82 #include "addincfg.hxx"
83 #include "tabvwsh.hxx"
84 #include "prevwsh.hxx"
85 #include "docsh.hxx"
86 #include "drwlayer.hxx"
87 #include "uiitems.hxx"
88 #include "sc.hrc"
89 #include "cfgids.hxx"
90 #include "inputhdl.hxx"
91 #include "inputwin.hxx"
92 #include "msgpool.hxx"
93 #include "scresid.hxx"
94 #include "dwfunctr.hxx"
95 #include "formdata.hxx"
96 #include "tpprint.hxx"
97 #include "tpdefaults.hxx"
98 #include "transobj.hxx"
99 #include "detfunc.hxx"
100 #include "preview.hxx"
101 #include "dragdata.hxx"
102 #include "clipdata.hxx"
103 #include "markdata.hxx"
105 #include <svx/xmlsecctrl.hxx>
107 #define ScModule
108 #include "scslots.hxx"
110 #include "scabstdlg.hxx"
111 #include <formula/errorcodes.hxx>
112 #include "formulagroup.hxx"
113 #include <documentlinkmgr.hxx>
115 #define SC_IDLE_MIN 150
116 #define SC_IDLE_MAX 3000
117 #define SC_IDLE_STEP 75
118 #define SC_IDLE_COUNT 50
120 static sal_uInt16 nIdleCount = 0;
122 SFX_IMPL_INTERFACE(ScModule, SfxShell)
124 void ScModule::InitInterface_Impl()
126 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER,
127 RID_OBJECTBAR_APP);
129 GetStaticInterface()->RegisterStatusBar(ScResId(SCCFG_STATUSBAR));
132 ScModule::ScModule( SfxObjectFactory* pFact ) :
133 SfxModule( ResMgr::CreateResMgr( "sc" ), false, pFact, NULL ),
134 mpDragData(new ScDragData),
135 mpClipData(new ScClipData),
136 pSelTransfer( NULL ),
137 pMessagePool( NULL ),
138 pRefInputHandler( NULL ),
139 pViewCfg( NULL ),
140 pDocCfg( NULL ),
141 pAppCfg( NULL ),
142 pDefaultsCfg( NULL ),
143 pFormulaCfg( NULL ),
144 pInputCfg( NULL ),
145 pPrintCfg( NULL ),
146 pNavipiCfg( NULL ),
147 pAddInCfg( NULL ),
148 pColorConfig( NULL ),
149 pAccessOptions( NULL ),
150 pCTLOptions( NULL ),
151 pUserOptions( NULL ),
152 pErrorHdl( NULL ),
153 pFormEditData( NULL ),
154 nCurRefDlgId( 0 ),
155 bIsWaterCan( false ),
156 bIsInEditCommand( false ),
157 bIsInExecuteDrop( false ),
158 mbIsInSharedDocLoading( false ),
159 mbIsInSharedDocSaving( false )
161 // The ResManager (DLL data) is not yet initalized in the ctor!
162 SetName(OUString("StarCalc")); // for Basic
164 ResetDragObject();
165 SetClipObject( NULL, NULL );
167 // InputHandler does not need to be created
169 // Create ErrorHandler - was in Init()
170 // Between OfficeApplication::Init and ScGlobal::Init
171 SvxErrorHandler::ensure();
172 pErrorHdl = new SfxErrorHandler( RID_ERRHDLSC,
173 ERRCODE_AREA_SC,
174 ERRCODE_AREA_APP2-1,
175 GetResMgr() );
177 aSpellIdle.SetPriority(SchedulerPriority::LOWER);
178 aSpellIdle.SetIdleHdl( LINK( this, ScModule, SpellTimerHdl ) );
179 aIdleTimer.SetTimeout(SC_IDLE_MIN);
180 aIdleTimer.SetTimeoutHdl( LINK( this, ScModule, IdleHandler ) );
181 aIdleTimer.Start();
183 pMessagePool = new ScMessagePool;
184 pMessagePool->FreezeIdRanges();
185 SetPool( pMessagePool );
186 ScGlobal::InitTextHeight( pMessagePool );
188 StartListening( *SfxGetpApp() ); // for SFX_HINT_DEINITIALIZING
191 ScModule::~ScModule()
193 OSL_ENSURE( !pSelTransfer, "Selection Transfer object not deleted" );
195 // InputHandler does not need to be deleted (there's none in the App anymore)
197 SfxItemPool::Free(pMessagePool);
199 DELETEZ( pFormEditData );
201 delete mpDragData;
202 delete mpClipData;
203 delete pErrorHdl;
205 ScGlobal::Clear(); // Also calls ScDocumentPool::DeleteVersionMaps();
207 DeleteCfg(); // Called from Exit()
210 void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 )
212 if ( p == pColorConfig || p == pAccessOptions )
214 // Test if detective objects have to be updated with new colors
215 // (if the detective colors haven't been used yet, there's nothing to update)
216 if ( ScDetectiveFunc::IsColorsInitialized() )
218 const svtools::ColorConfig& rColors = GetColorConfig();
219 bool bArrows =
220 ( ScDetectiveFunc::GetArrowColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVE).nColor ||
221 ScDetectiveFunc::GetErrorColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVEERROR).nColor );
222 bool bComments =
223 ( ScDetectiveFunc::GetCommentColor() != (ColorData)rColors.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor );
224 if ( bArrows || bComments )
226 ScDetectiveFunc::InitializeColors(); // get the new colors
228 // update detective objects in all open documents
229 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
230 while ( pObjSh )
232 if ( pObjSh->Type() == TYPE(ScDocShell) )
234 ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);
235 if ( bArrows )
236 ScDetectiveFunc( &pDocSh->GetDocument(), 0 ).UpdateAllArrowColors();
237 if ( bComments )
238 ScDetectiveFunc::UpdateAllComments( pDocSh->GetDocument() );
240 pObjSh = SfxObjectShell::GetNext( *pObjSh );
245 // force all views to repaint, using the new options
246 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
247 while(pViewShell)
249 if ( pViewShell->ISA(ScTabViewShell) )
251 ScTabViewShell* pViewSh = static_cast<ScTabViewShell*>(pViewShell);
252 pViewSh->PaintGrid();
253 pViewSh->PaintTop();
254 pViewSh->PaintLeft();
255 pViewSh->PaintExtras();
257 ScInputHandler* pHdl = pViewSh->GetInputHandler();
258 if ( pHdl )
259 pHdl->ForgetLastPattern(); // EditEngine BackgroundColor may change
261 else if ( pViewShell->ISA(ScPreviewShell) )
263 vcl::Window* pWin = pViewShell->GetWindow();
264 if (pWin)
265 pWin->Invalidate();
267 pViewShell = SfxViewShell::GetNext( *pViewShell );
270 else if ( p == pCTLOptions )
272 // for all documents: set digit language for printer, recalc output factor, update row heights
273 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
274 while ( pObjSh )
276 if ( pObjSh->Type() == TYPE(ScDocShell) )
278 ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);
279 OutputDevice* pPrinter = pDocSh->GetPrinter();
280 if ( pPrinter )
281 pPrinter->SetDigitLanguage( GetOptDigitLanguage() );
283 pDocSh->CalcOutputFactor();
285 SCTAB nTabCount = pDocSh->GetDocument().GetTableCount();
286 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
287 pDocSh->AdjustRowHeight( 0, MAXROW, nTab );
289 pObjSh = SfxObjectShell::GetNext( *pObjSh );
292 // for all views (table and preview): update digit language
293 SfxViewShell* pSh = SfxViewShell::GetFirst();
294 while ( pSh )
296 if ( pSh->ISA( ScTabViewShell ) )
298 ScTabViewShell* pViewSh = static_cast<ScTabViewShell*>(pSh);
300 // set ref-device for EditEngine (re-evaluates digit settings)
301 ScInputHandler* pHdl = GetInputHdl(pViewSh);
302 if (pHdl)
303 pHdl->UpdateRefDevice();
305 pViewSh->DigitLanguageChanged();
306 pViewSh->PaintGrid();
308 else if ( pSh->ISA( ScPreviewShell ) )
310 ScPreviewShell* pPreviewSh = static_cast<ScPreviewShell*>(pSh);
311 ScPreview* pPreview = pPreviewSh->GetPreview();
313 pPreview->SetDigitLanguage( GetOptDigitLanguage() );
314 pPreview->Invalidate();
317 pSh = SfxViewShell::GetNext( *pSh );
322 void ScModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
324 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
325 if ( pSimpleHint )
327 sal_uLong nHintId = pSimpleHint->GetId();
328 if ( nHintId == SFX_HINT_DEINITIALIZING )
330 // ConfigItems must be removed before ConfigManager
331 DeleteCfg();
336 void ScModule::DeleteCfg()
338 DELETEZ( pViewCfg ); // Saving happens automatically before Exit()
339 DELETEZ( pDocCfg );
340 DELETEZ( pAppCfg );
341 DELETEZ( pDefaultsCfg );
342 DELETEZ( pFormulaCfg );
343 DELETEZ( pInputCfg );
344 DELETEZ( pPrintCfg );
345 DELETEZ( pNavipiCfg );
346 DELETEZ( pAddInCfg );
348 if ( pColorConfig )
350 pColorConfig->RemoveListener(this);
351 DELETEZ( pColorConfig );
353 if ( pAccessOptions )
355 pAccessOptions->RemoveListener(this);
356 DELETEZ( pAccessOptions );
358 if ( pCTLOptions )
360 pCTLOptions->RemoveListener(this);
361 DELETEZ( pCTLOptions );
363 if( pUserOptions )
365 DELETEZ( pUserOptions );
369 // Moved here from the App
371 void ScModule::Execute( SfxRequest& rReq )
373 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
374 SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : NULL;
376 const SfxItemSet* pReqArgs = rReq.GetArgs();
377 sal_uInt16 nSlot = rReq.GetSlot();
379 switch ( nSlot )
381 case SID_CHOOSE_DESIGN:
383 OUString aMacroName("Template.Samples.ShowStyles");
384 SfxApplication::CallAppBasic( aMacroName );
386 break;
387 case SID_EURO_CONVERTER:
389 OUString aMacroName("Euro.ConvertRun.Main");
390 SfxApplication::CallAppBasic( aMacroName );
392 break;
393 case SID_AUTOSPELL_CHECK:
395 bool bSet;
396 const SfxPoolItem* pItem;
397 if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
398 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
399 else
400 { // Toggle
401 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
402 if ( pDocSh )
403 bSet = !pDocSh->GetDocument().GetDocOptions().IsAutoSpell();
404 else
405 bSet = !GetDocOptions().IsAutoSpell();
408 SfxItemSet aSet( GetPool(), SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK );
409 aSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, bSet ) );
410 ModifyOptions( aSet );
411 rReq.Done();
413 break;
415 case SID_ATTR_METRIC:
417 const SfxPoolItem* pItem;
418 if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( nSlot, true, &pItem ) )
420 FieldUnit eUnit = (FieldUnit)static_cast<const SfxUInt16Item*>(pItem)->GetValue();
421 switch( eUnit )
423 case FUNIT_MM: // Just the units that are also in the dialog
424 case FUNIT_CM:
425 case FUNIT_INCH:
426 case FUNIT_PICA:
427 case FUNIT_POINT:
429 PutItem( *pItem );
430 ScAppOptions aNewOpts( GetAppOptions() );
431 aNewOpts.SetAppMetric( eUnit );
432 SetAppOptions( aNewOpts );
433 rReq.Done();
435 break;
436 default:
438 // added to avoid warnings
443 break;
445 case FID_AUTOCOMPLETE:
447 ScAppOptions aNewOpts( GetAppOptions() );
448 bool bNew = !aNewOpts.GetAutoComplete();
449 aNewOpts.SetAutoComplete( bNew );
450 SetAppOptions( aNewOpts );
451 ScInputHandler::SetAutoComplete( bNew );
452 if (pBindings)
453 pBindings->Invalidate( FID_AUTOCOMPLETE );
454 rReq.Done();
456 break;
458 case SID_DETECTIVE_AUTO:
460 ScAppOptions aNewOpts( GetAppOptions() );
461 bool bNew = !aNewOpts.GetDetectiveAuto();
462 SFX_REQUEST_ARG( rReq, pAuto, SfxBoolItem, SID_DETECTIVE_AUTO, false );
463 if ( pAuto )
464 bNew = pAuto->GetValue();
466 aNewOpts.SetDetectiveAuto( bNew );
467 SetAppOptions( aNewOpts );
468 if (pBindings)
469 pBindings->Invalidate( SID_DETECTIVE_AUTO );
470 rReq.AppendItem( SfxBoolItem( SID_DETECTIVE_AUTO, bNew ) );
471 rReq.Done();
473 break;
475 case SID_PSZ_FUNCTION:
476 if (pReqArgs)
478 const SfxUInt16Item& rItem = static_cast<const SfxUInt16Item&>(pReqArgs->Get(SID_PSZ_FUNCTION));
479 OSL_ENSURE(rItem.ISA(SfxUInt16Item),"wrong Parameter");
481 ScAppOptions aNewOpts( GetAppOptions() );
482 aNewOpts.SetStatusFunc( rItem.GetValue() );
483 SetAppOptions( aNewOpts );
485 if (pBindings)
487 pBindings->Invalidate( SID_TABLE_CELL );
488 pBindings->Update( SID_TABLE_CELL ); // Immediately
490 pBindings->Invalidate( SID_PSZ_FUNCTION );
491 pBindings->Update( SID_PSZ_FUNCTION );
492 // If the menu is opened again immediately
495 break;
497 case SID_ATTR_LANGUAGE:
498 case SID_ATTR_CHAR_CJK_LANGUAGE:
499 case SID_ATTR_CHAR_CTL_LANGUAGE:
501 const SfxPoolItem* pItem;
502 if ( pReqArgs && SfxItemState::SET == pReqArgs->GetItemState( GetPool().GetWhich(nSlot), true, &pItem ) )
504 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
505 if ( pDocSh )
507 ScDocument& rDoc = pDocSh->GetDocument();
508 LanguageType eNewLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
509 LanguageType eLatin, eCjk, eCtl;
510 rDoc.GetLanguage( eLatin, eCjk, eCtl );
511 LanguageType eOld = ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE ) ? eCjk :
512 ( ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE ) ? eCtl : eLatin );
513 if ( eNewLang != eOld )
515 if ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE )
516 eCjk = eNewLang;
517 else if ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE )
518 eCtl = eNewLang;
519 else
520 eLatin = eNewLang;
522 rDoc.SetLanguage( eLatin, eCjk, eCtl );
524 ScInputHandler* pInputHandler = GetInputHdl();
525 if ( pInputHandler )
526 pInputHandler->UpdateSpellSettings(); // EditEngine flags
527 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
528 if ( pViewSh )
529 pViewSh->UpdateDrawTextOutliner(); // EditEngine flags
531 pDocSh->SetDocumentModified();
536 break;
538 case FID_FOCUS_POSWND:
540 ScInputHandler* pHdl = GetInputHdl();
541 if (pHdl)
543 ScInputWindow* pWin = pHdl->GetInputWindow();
544 if (pWin)
545 pWin->PosGrabFocus();
547 rReq.Done();
549 break;
551 case SID_OPEN_XML_FILTERSETTINGS:
555 css::uno::Reference < css::ui::dialogs::XExecutableDialog > xDialog = css::ui::dialogs::XSLTFilterDialog::create( ::comphelper::getProcessComponentContext());
556 xDialog->execute();
558 catch( ::com::sun::star::uno::RuntimeException& )
560 DBG_UNHANDLED_EXCEPTION();
563 break;
565 default:
566 OSL_FAIL( "ScApplication: Unknown Message." );
567 break;
571 void ScModule::GetState( SfxItemSet& rSet )
573 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
574 bool bTabView = pDocSh && (pDocSh->GetBestViewShell(true) != NULL);
576 SfxWhichIter aIter(rSet);
577 for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
579 if (!bTabView)
581 // Not in the normal calc view shell (most likely in preview shell). Disable all actions.
582 rSet.DisableItem(nWhich);
583 continue;
586 switch ( nWhich )
588 case FID_AUTOCOMPLETE:
589 rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetAutoComplete() ) );
590 break;
591 case SID_DETECTIVE_AUTO:
592 rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetDetectiveAuto() ) );
593 break;
594 case SID_PSZ_FUNCTION:
595 rSet.Put( SfxUInt16Item( nWhich, GetAppOptions().GetStatusFunc() ) );
596 break;
597 case SID_ATTR_METRIC:
598 rSet.Put( SfxUInt16Item( nWhich, sal::static_int_cast<sal_uInt16>(GetAppOptions().GetAppMetric()) ) );
599 break;
600 case SID_AUTOSPELL_CHECK:
601 rSet.Put( SfxBoolItem( nWhich, pDocSh->GetDocument().GetDocOptions().IsAutoSpell()) );
602 break;
603 case SID_ATTR_LANGUAGE:
604 case ATTR_CJK_FONT_LANGUAGE: // WID for SID_ATTR_CHAR_CJK_LANGUAGE
605 case ATTR_CTL_FONT_LANGUAGE: // WID for SID_ATTR_CHAR_CTL_LANGUAGE
607 LanguageType eLatin, eCjk, eCtl;
608 pDocSh->GetDocument().GetLanguage( eLatin, eCjk, eCtl );
609 LanguageType eLang = ( nWhich == ATTR_CJK_FONT_LANGUAGE ) ? eCjk :
610 ( ( nWhich == ATTR_CTL_FONT_LANGUAGE ) ? eCtl : eLatin );
611 rSet.Put( SvxLanguageItem( eLang, nWhich ) );
613 break;
618 void ScModule::HideDisabledSlots( SfxItemSet& rSet )
620 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
622 SfxBindings& rBindings = pViewFrm->GetBindings();
623 SfxWhichIter aIter( rSet );
624 for( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich != 0; nWhich = aIter.NextWhich() )
626 ScViewUtil::HideDisabledSlot( rSet, rBindings, nWhich );
627 // always disable the slots
628 rSet.DisableItem( nWhich );
633 void ScModule::ResetDragObject()
635 mpDragData->pCellTransfer = NULL;
636 mpDragData->pDrawTransfer = NULL;
637 mpDragData->pJumpLocalDoc = NULL;
638 (mpDragData->aLinkDoc).clear();
639 (mpDragData->aLinkTable).clear();
640 (mpDragData->aLinkArea).clear();
641 (mpDragData->aJumpTarget).clear();
642 (mpDragData->aJumpText).clear();
645 void ScModule::SetDragObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
647 ResetDragObject();
648 mpDragData->pCellTransfer = pCellObj;
649 mpDragData->pDrawTransfer = pDrawObj;
652 void ScModule::SetDragLink(
653 const OUString& rDoc, const OUString& rTab, const OUString& rArea )
655 ResetDragObject();
656 mpDragData->aLinkDoc = rDoc;
657 mpDragData->aLinkTable = rTab;
658 mpDragData->aLinkArea = rArea;
661 void ScModule::SetDragJump(
662 ScDocument* pLocalDoc, const OUString& rTarget, const OUString& rText )
664 ResetDragObject();
666 mpDragData->pJumpLocalDoc = pLocalDoc;
667 mpDragData->aJumpTarget = rTarget;
668 mpDragData->aJumpText = rText;
671 void ScModule::SetClipObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
673 OSL_ENSURE( !pCellObj || !pDrawObj, "SetClipObject: not allowed to set both objects" );
675 mpClipData->pCellClipboard = pCellObj;
676 mpClipData->pDrawClipboard = pDrawObj;
679 ScDocument* ScModule::GetClipDoc()
681 // called from document
682 ScTransferObj* pObj = ScTransferObj::GetOwnClipboard( NULL );
683 if (pObj)
684 return pObj->GetDocument();
686 return NULL;
689 void ScModule::SetSelectionTransfer( ScSelectionTransferObj* pNew )
691 pSelTransfer = pNew;
694 void ScModule::InitFormEditData()
696 pFormEditData = new ScFormEditData;
699 void ScModule::ClearFormEditData()
701 DELETEZ( pFormEditData );
704 void ScModule::SetViewOptions( const ScViewOptions& rOpt )
706 if ( !pViewCfg )
707 pViewCfg = new ScViewCfg;
709 pViewCfg->SetOptions( rOpt );
712 const ScViewOptions& ScModule::GetViewOptions()
714 if ( !pViewCfg )
715 pViewCfg = new ScViewCfg;
717 return *pViewCfg;
720 void ScModule::SetDocOptions( const ScDocOptions& rOpt )
722 if ( !pDocCfg )
723 pDocCfg = new ScDocCfg;
725 pDocCfg->SetOptions( rOpt );
728 const ScDocOptions& ScModule::GetDocOptions()
730 if ( !pDocCfg )
731 pDocCfg = new ScDocCfg;
733 return *pDocCfg;
736 #ifndef LRU_MAX
737 #define LRU_MAX 10
738 #endif
740 void ScModule::InsertEntryToLRUList(sal_uInt16 nFIndex)
742 if(nFIndex != 0)
744 const ScAppOptions& rAppOpt = GetAppOptions();
745 sal_uInt16 nLRUFuncCount = std::min( rAppOpt.GetLRUFuncListCount(), (sal_uInt16)LRU_MAX );
746 sal_uInt16* pLRUListIds = rAppOpt.GetLRUFuncList();
748 sal_uInt16 aIdxList[LRU_MAX];
749 sal_uInt16 n = 0;
750 bool bFound = false;
752 while ((n < LRU_MAX) && n<nLRUFuncCount) // Iterate through old list
754 if (!bFound && (pLRUListIds[n]== nFIndex))
755 bFound = true; // First hit!
756 else if (bFound)
757 aIdxList[n ] = pLRUListIds[n]; // Copy after hit
758 else if ((n+1) < LRU_MAX)
759 aIdxList[n+1] = pLRUListIds[n]; // Move before hit
760 n++;
762 if (!bFound && (n < LRU_MAX)) // Entry not found?
763 n++; // One more
764 aIdxList[0] = nFIndex; // Current on Top
766 ScAppOptions aNewOpts(rAppOpt); // Let App know
767 aNewOpts.SetLRUFuncList(aIdxList, n);
768 SetAppOptions(aNewOpts);
770 RecentFunctionsChanged();
774 void ScModule::RecentFunctionsChanged()
776 // update function list window
777 sal_uInt16 nFuncListID = ScFunctionChildWindow::GetChildWindowId();
779 //! notify all views
780 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
781 if (pViewFrm && pViewFrm->HasChildWindow(nFuncListID))
783 ScFunctionChildWindow* pWnd = static_cast<ScFunctionChildWindow*>(pViewFrm->GetChildWindow(nFuncListID));
784 if (!pWnd)
785 return;
786 ScFunctionDockWin* pFuncList = static_cast<ScFunctionDockWin*>(pWnd->GetWindow());
787 pFuncList->InitLRUList();
791 void ScModule::SetAppOptions( const ScAppOptions& rOpt )
793 if ( !pAppCfg )
794 pAppCfg = new ScAppCfg;
796 pAppCfg->SetOptions( rOpt );
799 void global_InitAppOptions()
801 SC_MOD()->GetAppOptions();
804 const ScAppOptions& ScModule::GetAppOptions()
806 if ( !pAppCfg )
807 pAppCfg = new ScAppCfg;
809 return *pAppCfg;
812 void ScModule::SetDefaultsOptions( const ScDefaultsOptions& rOpt )
814 if ( !pDefaultsCfg )
815 pDefaultsCfg = new ScDefaultsCfg;
817 pDefaultsCfg->SetOptions( rOpt );
820 const ScDefaultsOptions& ScModule::GetDefaultsOptions()
822 if ( !pDefaultsCfg )
823 pDefaultsCfg = new ScDefaultsCfg;
825 return *pDefaultsCfg;
828 void ScModule::SetFormulaOptions( const ScFormulaOptions& rOpt )
830 if ( !pFormulaCfg )
831 pFormulaCfg = new ScFormulaCfg;
833 pFormulaCfg->SetOptions( rOpt );
836 const ScFormulaOptions& ScModule::GetFormulaOptions()
838 if ( !pFormulaCfg )
839 pFormulaCfg = new ScFormulaCfg;
841 return *pFormulaCfg;
844 void ScModule::SetInputOptions( const ScInputOptions& rOpt )
846 if ( !pInputCfg )
847 pInputCfg = new ScInputCfg;
849 pInputCfg->SetOptions( rOpt );
852 const ScInputOptions& ScModule::GetInputOptions()
854 if ( !pInputCfg )
855 pInputCfg = new ScInputCfg;
857 return *pInputCfg;
860 void ScModule::SetPrintOptions( const ScPrintOptions& rOpt )
862 if ( !pPrintCfg )
863 pPrintCfg = new ScPrintCfg;
865 pPrintCfg->SetOptions( rOpt );
868 const ScPrintOptions& ScModule::GetPrintOptions()
870 if ( !pPrintCfg )
871 pPrintCfg = new ScPrintCfg;
873 return *pPrintCfg;
876 ScNavipiCfg& ScModule::GetNavipiCfg()
878 if ( !pNavipiCfg )
879 pNavipiCfg = new ScNavipiCfg;
881 return *pNavipiCfg;
884 ScAddInCfg& ScModule::GetAddInCfg()
886 if ( !pAddInCfg )
887 pAddInCfg = new ScAddInCfg;
889 return *pAddInCfg;
892 svtools::ColorConfig& ScModule::GetColorConfig()
894 if ( !pColorConfig )
896 pColorConfig = new svtools::ColorConfig;
897 pColorConfig->AddListener(this);
900 return *pColorConfig;
903 SvtAccessibilityOptions& ScModule::GetAccessOptions()
905 if ( !pAccessOptions )
907 pAccessOptions = new SvtAccessibilityOptions;
908 pAccessOptions->AddListener(this);
911 return *pAccessOptions;
914 SvtCTLOptions& ScModule::GetCTLOptions()
916 if ( !pCTLOptions )
918 pCTLOptions = new SvtCTLOptions;
919 pCTLOptions->AddListener(this);
922 return *pCTLOptions;
925 SvtUserOptions& ScModule::GetUserOptions()
927 if( !pUserOptions )
929 pUserOptions = new SvtUserOptions;
931 return *pUserOptions;
934 sal_uInt16 ScModule::GetOptDigitLanguage()
936 SvtCTLOptions::TextNumerals eNumerals = GetCTLOptions().GetCTLTextNumerals();
937 return ( eNumerals == SvtCTLOptions::NUMERALS_ARABIC ) ? LANGUAGE_ENGLISH_US :
938 ( eNumerals == SvtCTLOptions::NUMERALS_HINDI) ? LANGUAGE_ARABIC_SAUDI_ARABIA :
939 LANGUAGE_SYSTEM;
943 * Options
945 * Items from Calc options dialog and SID_AUTOSPELL_CHECK
947 void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
949 sal_uInt16 nOldSpellLang, nOldCjkLang, nOldCtlLang;
950 bool bOldAutoSpell;
951 GetSpellSettings( nOldSpellLang, nOldCjkLang, nOldCtlLang, bOldAutoSpell );
953 if (!pAppCfg)
954 GetAppOptions();
955 OSL_ENSURE( pAppCfg, "AppOptions not initialised :-(" );
957 if (!pInputCfg)
958 GetInputOptions();
959 OSL_ENSURE( pInputCfg, "InputOptions not initialised :-(" );
961 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
962 SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : NULL;
964 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
965 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
966 ScDocument* pDoc = pDocSh ? &pDocSh->GetDocument() : NULL;
967 const SfxPoolItem* pItem = NULL;
968 bool bRepaint = false;
969 bool bUpdateMarks = false;
970 bool bUpdateRefDev = false;
971 bool bCalcAll = false;
972 bool bSaveAppOptions = false;
973 bool bSaveInputOptions = false;
974 bool bCompileErrorCells = false;
976 // SfxGetpApp()->SetOptions( rOptSet );
978 // No more linguistics
979 if (rOptSet.HasItem(SID_ATTR_METRIC, &pItem))
981 PutItem( *pItem );
982 pAppCfg->SetAppMetric( (FieldUnit)static_cast<const SfxUInt16Item*>(pItem)->GetValue() );
983 bSaveAppOptions = true;
986 if (rOptSet.HasItem(SCITEM_USERLIST, &pItem))
988 ScGlobal::SetUserList( static_cast<const ScUserListItem*>(pItem)->GetUserList() );
989 bSaveAppOptions = true;
992 if (rOptSet.HasItem(SID_SC_OPT_SYNCZOOM, &pItem))
994 pAppCfg->SetSynchronizeZoom( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
995 bSaveAppOptions = true;
998 if (rOptSet.HasItem(SID_SC_OPT_KEY_BINDING_COMPAT, &pItem))
1000 sal_uInt16 nVal = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1001 ScOptionsUtil::KeyBindingType eOld = pAppCfg->GetKeyBindingType();
1002 ScOptionsUtil::KeyBindingType eNew = static_cast<ScOptionsUtil::KeyBindingType>(nVal);
1003 if (eOld != eNew)
1005 pAppCfg->SetKeyBindingType(eNew);
1006 bSaveAppOptions = true;
1007 ScDocShell::ResetKeyBindings(eNew);
1011 // DefaultsOptions
1012 if (rOptSet.HasItem(SID_SCDEFAULTSOPTIONS, &pItem))
1014 const ScDefaultsOptions& rOpt = static_cast<const ScTpDefaultsItem*>(pItem)->GetDefaultsOptions();
1015 SetDefaultsOptions( rOpt );
1018 // FormulaOptions
1019 if (rOptSet.HasItem(SID_SCFORMULAOPTIONS, &pItem))
1021 const ScFormulaOptions& rOpt = static_cast<const ScTpFormulaItem*>(pItem)->GetFormulaOptions();
1023 if (!pFormulaCfg || (*pFormulaCfg != rOpt))
1024 // Formula options have changed. Repaint the column headers.
1025 bRepaint = true;
1027 if (pFormulaCfg && pFormulaCfg->GetUseEnglishFuncName() != rOpt.GetUseEnglishFuncName())
1029 // Re-compile formula cells with error as the error may have been
1030 // caused by unresolved function names.
1031 bCompileErrorCells = true;
1034 // Recalc for interpreter options changes.
1035 if (pFormulaCfg && pFormulaCfg->GetCalcConfig() != rOpt.GetCalcConfig())
1036 bCalcAll = true;
1038 if ( pDocSh )
1040 pDocSh->SetFormulaOptions( rOpt );
1041 pDocSh->SetDocumentModified();
1044 // ScDocShell::SetFormulaOptions() may check for changed settings, so
1045 // set the new options here after that has been called.
1046 SetFormulaOptions( rOpt );
1049 // ViewOptions
1050 if (rOptSet.HasItem(SID_SCVIEWOPTIONS, &pItem))
1052 const ScViewOptions& rNewOpt = static_cast<const ScTpViewItem*>(pItem)->GetViewOptions();
1054 if ( pViewSh )
1056 ScViewData& rViewData = pViewSh->GetViewData();
1057 const ScViewOptions& rOldOpt = rViewData.GetOptions();
1059 bool bAnchorList = ( rOldOpt.GetOption( VOPT_ANCHOR ) !=
1060 rNewOpt.GetOption( VOPT_ANCHOR ) );
1062 if ( rOldOpt != rNewOpt )
1064 rViewData.SetOptions( rNewOpt ); // Changes rOldOpt
1065 rViewData.GetDocument()->SetViewOptions( rNewOpt );
1066 if (pDocSh)
1067 pDocSh->SetDocumentModified();
1068 bRepaint = true;
1070 if ( bAnchorList )
1071 pViewSh->UpdateAnchorHandles();
1073 SetViewOptions( rNewOpt );
1074 if (pBindings)
1076 pBindings->Invalidate(SID_HELPLINES_MOVE);
1080 // GridOptions
1081 // Evaluate after ViewOptions, as GridOptions is a member of ViewOptions
1082 if ( rOptSet.HasItem(SID_ATTR_GRID_OPTIONS,&pItem) )
1084 ScGridOptions aNewGridOpt( static_cast<const SvxGridItem&>(*pItem ));
1086 if ( pViewSh )
1088 ScViewData& rViewData = pViewSh->GetViewData();
1089 ScViewOptions aNewViewOpt( rViewData.GetOptions() );
1090 const ScGridOptions& rOldGridOpt = aNewViewOpt.GetGridOptions();
1092 if ( rOldGridOpt != aNewGridOpt )
1094 aNewViewOpt.SetGridOptions( aNewGridOpt );
1095 rViewData.SetOptions( aNewViewOpt );
1096 rViewData.GetDocument()->SetViewOptions( aNewViewOpt );
1097 pDocSh->SetDocumentModified();
1098 bRepaint = true;
1101 ScViewOptions aNewViewOpt ( GetViewOptions() );
1102 aNewViewOpt.SetGridOptions( aNewGridOpt );
1103 SetViewOptions( aNewViewOpt );
1104 if (pBindings)
1106 pBindings->Invalidate(SID_GRID_VISIBLE);
1107 pBindings->Invalidate(SID_GRID_USE);
1111 // DocOptions
1112 if ( rOptSet.HasItem(SID_SCDOCOPTIONS,&pItem) )
1114 const ScDocOptions& rNewOpt = static_cast<const ScTpCalcItem*>(pItem)->GetDocOptions();
1116 if ( pDoc )
1118 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1120 bRepaint = ( bRepaint || ( rOldOpt != rNewOpt ) );
1121 bCalcAll = bRepaint &&
1122 ( rOldOpt.IsIter() != rNewOpt.IsIter()
1123 || rOldOpt.GetIterCount() != rNewOpt.GetIterCount()
1124 || rOldOpt.GetIterEps() != rNewOpt.GetIterEps()
1125 || rOldOpt.IsIgnoreCase() != rNewOpt.IsIgnoreCase()
1126 || rOldOpt.IsCalcAsShown() != rNewOpt.IsCalcAsShown()
1127 || (rNewOpt.IsCalcAsShown() &&
1128 rOldOpt.GetStdPrecision() != rNewOpt.GetStdPrecision())
1129 || rOldOpt.IsMatchWholeCell() != rNewOpt.IsMatchWholeCell()
1130 || rOldOpt.GetYear2000() != rNewOpt.GetYear2000()
1131 || rOldOpt.IsFormulaRegexEnabled() != rNewOpt.IsFormulaRegexEnabled()
1133 pDoc->SetDocOptions( rNewOpt );
1134 pDocSh->SetDocumentModified();
1136 SetDocOptions( rNewOpt );
1139 // Set TabDistance after the actual DocOptions
1140 if ( rOptSet.HasItem(SID_ATTR_DEFTABSTOP,&pItem) )
1142 sal_uInt16 nTabDist = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1143 ScDocOptions aOpt(GetDocOptions());
1144 aOpt.SetTabDistance(nTabDist);
1145 SetDocOptions( aOpt );
1147 if ( pDoc )
1149 ScDocOptions aDocOpt(pDoc->GetDocOptions());
1150 aDocOpt.SetTabDistance(nTabDist);
1151 pDoc->SetDocOptions( aDocOpt );
1152 pDocSh->SetDocumentModified();
1153 if(pDoc->GetDrawLayer())
1154 pDoc->GetDrawLayer()->SetDefaultTabulator(nTabDist);
1158 // AutoSpell after the DocOptions (due to being a member)
1159 if ( rOptSet.HasItem(SID_AUTOSPELL_CHECK,&pItem) ) // At DocOptions
1161 bool bDoAutoSpell = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1163 if (pDoc)
1165 ScDocOptions aNewOpt = pDoc->GetDocOptions();
1166 if ( aNewOpt.IsAutoSpell() != bDoAutoSpell )
1168 aNewOpt.SetAutoSpell( bDoAutoSpell );
1169 pDoc->SetDocOptions( aNewOpt );
1171 if (pViewSh)
1172 pViewSh->EnableAutoSpell(bDoAutoSpell);
1174 bRepaint = true; // Because HideAutoSpell might be invalid
1175 //TODO: Paint all Views?
1179 if ( bOldAutoSpell != bDoAutoSpell )
1180 SetAutoSpellProperty( bDoAutoSpell );
1181 if ( pDocSh )
1182 pDocSh->PostPaintGridAll(); // Due to marks
1183 ScInputHandler* pInputHandler = GetInputHdl();
1184 if ( pInputHandler )
1185 pInputHandler->UpdateSpellSettings(); // EditEngine flags
1186 if ( pViewSh )
1187 pViewSh->UpdateDrawTextOutliner(); // EditEngine flags
1189 if (pBindings)
1190 pBindings->Invalidate( SID_AUTOSPELL_CHECK );
1193 // InputOptions
1194 if ( rOptSet.HasItem(SID_SC_INPUT_SELECTIONPOS,&pItem) )
1196 pInputCfg->SetMoveDir( static_cast<const SfxUInt16Item*>(pItem)->GetValue() );
1197 bSaveInputOptions = true;
1199 if ( rOptSet.HasItem(SID_SC_INPUT_SELECTION,&pItem) )
1201 pInputCfg->SetMoveSelection( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1202 bSaveInputOptions = true;
1204 if ( rOptSet.HasItem(SID_SC_INPUT_EDITMODE,&pItem) )
1206 pInputCfg->SetEnterEdit( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1207 bSaveInputOptions = true;
1209 if ( rOptSet.HasItem(SID_SC_INPUT_FMT_EXPAND,&pItem) )
1211 pInputCfg->SetExtendFormat( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1212 bSaveInputOptions = true;
1214 if ( rOptSet.HasItem(SID_SC_INPUT_RANGEFINDER,&pItem) )
1216 pInputCfg->SetRangeFinder( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1217 bSaveInputOptions = true;
1219 if ( rOptSet.HasItem(SID_SC_INPUT_REF_EXPAND,&pItem) )
1221 pInputCfg->SetExpandRefs( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1222 bSaveInputOptions = true;
1224 if (rOptSet.HasItem(SID_SC_OPT_SORT_REF_UPDATE, &pItem))
1226 pInputCfg->SetSortRefUpdate(static_cast<const SfxBoolItem*>(pItem)->GetValue());
1227 bSaveInputOptions = true;
1230 if ( rOptSet.HasItem(SID_SC_INPUT_MARK_HEADER,&pItem) )
1232 pInputCfg->SetMarkHeader( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1233 bSaveInputOptions = true;
1234 bUpdateMarks = true;
1236 if ( rOptSet.HasItem(SID_SC_INPUT_TEXTWYSIWYG,&pItem) )
1238 bool bNew = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1239 if ( bNew != pInputCfg->GetTextWysiwyg() )
1241 pInputCfg->SetTextWysiwyg( bNew );
1242 bSaveInputOptions = true;
1243 bUpdateRefDev = true;
1246 if( rOptSet.HasItem( SID_SC_INPUT_REPLCELLSWARN, &pItem ) )
1248 pInputCfg->SetReplaceCellsWarn( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1249 bSaveInputOptions = true;
1252 if( rOptSet.HasItem( SID_SC_INPUT_LEGACY_CELL_SELECTION, &pItem ) )
1254 pInputCfg->SetLegacyCellSelection( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1255 bSaveInputOptions = true;
1258 // PrintOptions
1259 if ( rOptSet.HasItem(SID_SCPRINTOPTIONS,&pItem) )
1261 const ScPrintOptions& rNewOpt = static_cast<const ScTpPrintItem*>(pItem)->GetPrintOptions();
1262 SetPrintOptions( rNewOpt );
1264 // broadcast causes all previews to recalc page numbers
1265 SfxGetpApp()->Broadcast( SfxSimpleHint( SID_SCPRINTOPTIONS ) );
1268 if ( bSaveAppOptions )
1269 pAppCfg->OptionsChanged();
1271 if ( bSaveInputOptions )
1272 pInputCfg->OptionsChanged();
1274 // Kick off recalculation?
1275 if (pDoc && bCompileErrorCells)
1277 // Re-compile cells with name error, and recalc if at least one cell
1278 // has been re-compiled. In the future we may want to find a way to
1279 // recalc only those that are affected.
1280 if (pDoc->CompileErrorCells(ScErrorCodes::errNoName))
1281 bCalcAll = true;
1284 if ( pDoc && bCalcAll )
1286 WaitObject aWait( ScDocShell::GetActiveDialogParent() );
1287 pDoc->CalcAll();
1288 if ( pViewSh )
1289 pViewSh->UpdateCharts( true );
1290 else
1291 ScDBFunc::DoUpdateCharts( ScAddress(), pDoc, true );
1292 if (pBindings)
1293 pBindings->Invalidate( SID_ATTR_SIZE ); //SvxPosSize StatusControl Update
1296 if ( pViewSh && bUpdateMarks )
1297 pViewSh->UpdateAutoFillMark();
1299 // Repaint View?
1300 if ( pViewSh && bRepaint )
1302 pViewSh->UpdateFixPos();
1303 pViewSh->PaintGrid();
1304 pViewSh->PaintTop();
1305 pViewSh->PaintLeft();
1306 pViewSh->PaintExtras();
1307 pViewSh->InvalidateBorder();
1308 if (pBindings)
1310 pBindings->Invalidate( FID_TOGGLEHEADERS ); // -> Checks in menu
1311 pBindings->Invalidate( FID_TOGGLESYNTAX );
1315 // update ref device (for all documents)
1316 if ( bUpdateRefDev )
1318 // for all documents: recalc output factor, update row heights
1319 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
1320 while ( pObjSh )
1322 if ( pObjSh->Type() == TYPE(ScDocShell) )
1324 ScDocShell* pOneDocSh = static_cast<ScDocShell*>(pObjSh);
1325 pOneDocSh->CalcOutputFactor();
1326 SCTAB nTabCount = pOneDocSh->GetDocument().GetTableCount();
1327 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1328 pOneDocSh->AdjustRowHeight( 0, MAXROW, nTab );
1330 pObjSh = SfxObjectShell::GetNext( *pObjSh );
1333 // for all (tab-) views:
1334 TypeId aScType = TYPE(ScTabViewShell);
1335 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
1336 while ( pSh )
1338 ScTabViewShell* pOneViewSh = static_cast<ScTabViewShell*>(pSh);
1340 // set ref-device for EditEngine
1341 ScInputHandler* pHdl = GetInputHdl(pOneViewSh);
1342 if (pHdl)
1343 pHdl->UpdateRefDevice();
1345 // update view scale
1346 ScViewData& rViewData = pOneViewSh->GetViewData();
1347 pOneViewSh->SetZoom( rViewData.GetZoomX(), rViewData.GetZoomY(), false );
1349 // repaint
1350 pOneViewSh->PaintGrid();
1351 pOneViewSh->PaintTop();
1352 pOneViewSh->PaintLeft();
1354 pSh = SfxViewShell::GetNext( *pSh, &aScType );
1360 * Input-Handler
1362 ScInputHandler* ScModule::GetInputHdl( ScTabViewShell* pViewSh, bool bUseRef )
1364 if ( pRefInputHandler && bUseRef )
1365 return pRefInputHandler;
1367 ScInputHandler* pHdl = NULL;
1368 if ( !pViewSh )
1370 // in case a UIActive embedded object has no ViewShell (UNO component)
1371 // the own calc view shell will be set as current, but no handling should happen
1372 ScTabViewShell* pCurViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
1373 if ( pCurViewSh && !pCurViewSh->GetUIActiveClient() )
1374 pViewSh = pCurViewSh;
1377 if ( pViewSh )
1378 pHdl = pViewSh->GetInputHandler(); // Viewshell always has one, from now on
1380 // If no ViewShell passed or active, we can get NULL
1381 OSL_ENSURE( pHdl || !pViewSh, "GetInputHdl: no InputHandler found!" );
1382 return pHdl;
1385 void ScModule::ViewShellChanged()
1387 ScInputHandler* pHdl = GetInputHdl();
1388 ScTabViewShell* pShell = ScTabViewShell::GetActiveViewShell();
1389 if ( pShell && pHdl )
1390 pShell->UpdateInputHandler();
1393 void ScModule::SetInputMode( ScInputMode eMode, const OUString* pInitText )
1395 ScInputHandler* pHdl = GetInputHdl();
1396 if (pHdl)
1397 pHdl->SetMode(eMode, pInitText);
1400 bool ScModule::IsEditMode()
1402 ScInputHandler* pHdl = GetInputHdl();
1403 return pHdl && pHdl->IsEditMode();
1406 bool ScModule::IsInputMode()
1408 ScInputHandler* pHdl = GetInputHdl();
1409 return pHdl && pHdl->IsInputMode();
1412 bool ScModule::InputKeyEvent( const KeyEvent& rKEvt, bool bStartEdit )
1414 ScInputHandler* pHdl = GetInputHdl();
1415 return pHdl && pHdl->KeyInput( rKEvt, bStartEdit );
1418 void ScModule::InputEnterHandler( sal_uInt8 nBlockMode )
1420 if ( !SfxGetpApp()->IsDowning() ) // Not when quitting the program
1422 ScInputHandler* pHdl = GetInputHdl();
1423 if (pHdl)
1424 pHdl->EnterHandler( nBlockMode );
1428 void ScModule::InputCancelHandler()
1430 ScInputHandler* pHdl = GetInputHdl();
1431 if (pHdl)
1432 pHdl->CancelHandler();
1435 void ScModule::InputSelection( EditView* pView )
1437 ScInputHandler* pHdl = GetInputHdl();
1438 if (pHdl)
1439 pHdl->InputSelection( pView );
1442 void ScModule::InputChanged( EditView* pView )
1444 ScInputHandler* pHdl = GetInputHdl();
1445 if (pHdl)
1446 pHdl->InputChanged( pView );
1449 void ScModule::ViewShellGone( ScTabViewShell* pViewSh )
1451 ScInputHandler* pHdl = GetInputHdl();
1452 if (pHdl)
1453 pHdl->ViewShellGone( pViewSh );
1456 void ScModule::SetRefInputHdl( ScInputHandler* pNew )
1458 pRefInputHandler = pNew;
1461 void ScModule::InputGetSelection( sal_Int32& rStart, sal_Int32& rEnd )
1463 ScInputHandler* pHdl = GetInputHdl();
1464 if (pHdl)
1465 pHdl->InputGetSelection( rStart, rEnd );
1468 void ScModule::InputSetSelection( sal_Int32 nStart, sal_Int32 nEnd )
1470 ScInputHandler* pHdl = GetInputHdl();
1471 if (pHdl)
1472 pHdl->InputSetSelection( nStart, nEnd );
1475 void ScModule::InputReplaceSelection( const OUString& rStr )
1477 ScInputHandler* pHdl = GetInputHdl();
1478 if (pHdl)
1479 pHdl->InputReplaceSelection( rStr );
1482 void ScModule::InputTurnOffWinEngine()
1484 ScInputHandler* pHdl = GetInputHdl();
1485 if (pHdl)
1486 pHdl->InputTurnOffWinEngine();
1489 OUString ScModule::InputGetFormulaStr()
1491 ScInputHandler* pHdl = GetInputHdl();
1492 OUString aStr;
1493 if ( pHdl )
1494 aStr = pHdl->GetFormString();
1495 return aStr;
1498 void ScModule::ActivateInputWindow( const OUString* pStrFormula, bool bMatrix )
1500 ScInputHandler* pHdl = GetInputHdl();
1501 if ( pHdl )
1503 ScInputWindow* pWin = pHdl->GetInputWindow();
1504 if ( pStrFormula )
1506 // Take over formula
1507 if ( pWin )
1509 pWin->SetFuncString( *pStrFormula, false );
1510 // SetSumAssignMode due to sal_False not necessary
1512 sal_uInt8 nMode = bMatrix ? SC_ENTER_MATRIX : SC_ENTER_NORMAL;
1513 pHdl->EnterHandler( nMode );
1515 // Without Invalidate the selection remains active, if the formula has not changed
1516 if (pWin)
1517 pWin->TextInvalidate();
1519 else
1521 // Cancel
1522 if ( pWin )
1524 pWin->SetFuncString( EMPTY_OUSTRING, false );
1525 // SetSumAssignMode due to sal_False no necessary
1527 pHdl->CancelHandler();
1533 * Reference dialogs
1535 void ScModule::SetRefDialog( sal_uInt16 nId, bool bVis, SfxViewFrame* pViewFrm )
1537 //TODO: Move reference dialog handling to view
1538 // Just keep function autopilot here for references to other documents
1539 if(nCurRefDlgId==0 || (nId==nCurRefDlgId && !bVis))
1541 if ( !pViewFrm )
1542 pViewFrm = SfxViewFrame::Current();
1544 // bindings update causes problems with update of stylist if
1545 // current style family has changed
1546 //if ( pViewFrm )
1547 // pViewFrm->GetBindings().Update(); // to avoid trouble in LockDispatcher
1549 nCurRefDlgId = bVis ? nId : 0 ; // before SetChildWindow
1551 if ( pViewFrm )
1553 // store the dialog id also in the view shell
1554 SfxViewShell* pViewSh = pViewFrm->GetViewShell();
1555 if ( pViewSh && pViewSh->ISA( ScTabViewShell ) )
1556 static_cast<ScTabViewShell*>(pViewSh)->SetCurRefDlgId( nCurRefDlgId );
1557 else
1559 // no ScTabViewShell - possible for example from a Basic macro
1560 bVis = false;
1561 nCurRefDlgId = 0; // don't set nCurRefDlgId if no dialog is created
1564 pViewFrm->SetChildWindow( nId, bVis );
1567 SfxApplication* pSfxApp = SfxGetpApp();
1568 pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) );
1572 static SfxChildWindow* lcl_GetChildWinFromAnyView( sal_uInt16 nId )
1574 // First, try the current view
1575 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1577 // #i46999# current view frame can be null (for example, when closing help)
1578 SfxChildWindow* pChildWnd = pViewFrm ? pViewFrm->GetChildWindow( nId ) : NULL;
1579 if ( pChildWnd )
1580 return pChildWnd; // found in the current view
1582 // if not found there, get the child window from any open view
1583 // it can be open only in one view because nCurRefDlgId is global
1585 pViewFrm = SfxViewFrame::GetFirst();
1586 while ( pViewFrm )
1588 pChildWnd = pViewFrm->GetChildWindow( nId );
1589 if ( pChildWnd )
1590 return pChildWnd; // found in any view
1592 pViewFrm = SfxViewFrame::GetNext( *pViewFrm );
1595 return NULL; // none found
1598 bool ScModule::IsModalMode(SfxObjectShell* pDocSh)
1600 //TODO: Move reference dialog handling to view
1601 // Just keep function autopilot here for references to other documents
1602 bool bIsModal = false;
1604 if ( nCurRefDlgId )
1606 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1607 if ( pChildWnd )
1609 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1610 assert(pRefDlg);
1611 bIsModal = pChildWnd->IsVisible() && pRefDlg &&
1612 !( pRefDlg->IsRefInputMode() && pRefDlg->IsDocAllowed(pDocSh) );
1614 else
1616 // in 592 and above, the dialog isn't visible in other views
1617 // if the dialog is open but can't be accessed, disable input
1618 bIsModal = true;
1621 // pChildWnd can be 0 if the dialog has not been created by another Shell yet after
1622 // switching over(e.g. in GetFocus())
1624 else if (pDocSh)
1626 ScInputHandler* pHdl = GetInputHdl();
1627 if ( pHdl )
1628 bIsModal = pHdl->IsModalMode(pDocSh);
1631 return bIsModal;
1634 bool ScModule::IsTableLocked()
1636 //TODO: Move reference dialog handling to view
1637 // Just keep function autopilot here for references to other documents
1638 bool bLocked = false;
1640 // Up until now just for ScAnyRefDlg
1641 if ( nCurRefDlgId )
1643 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1644 if ( pChildWnd )
1646 IAnyRefDialog* pRefDlg(dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow()));
1647 assert(pRefDlg);
1648 if(pRefDlg)
1650 bLocked = pRefDlg->IsTableLocked();
1653 else
1654 bLocked = true; // for other views, see IsModalMode
1657 return bLocked;
1660 bool ScModule::IsRefDialogOpen()
1662 //TODO: Move reference dialog handling to view
1663 // Just keep function autopilot here for references to other documents
1664 bool bIsOpen = false;
1666 if ( nCurRefDlgId )
1668 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1669 if ( pChildWnd )
1670 bIsOpen = pChildWnd->IsVisible();
1671 else
1672 bIsOpen = true; // for other views, see IsModalMode
1675 return bIsOpen;
1678 bool ScModule::IsFormulaMode()
1680 //TODO: Move reference dialog handling to view
1681 // Just keep function autopilot here for references to other documents
1682 bool bIsFormula = false;
1684 if ( nCurRefDlgId )
1686 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1687 if ( pChildWnd )
1689 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1690 assert(pRefDlg);
1691 bIsFormula = pChildWnd->IsVisible() && pRefDlg && pRefDlg->IsRefInputMode();
1693 else
1694 bIsFormula = true;
1696 else
1698 ScInputHandler* pHdl = GetInputHdl();
1699 if ( pHdl )
1700 bIsFormula = pHdl->IsFormulaMode();
1703 if (bIsInEditCommand)
1704 bIsFormula = true;
1706 return bIsFormula;
1709 static void lcl_MarkedTabs( const ScMarkData& rMark, SCTAB& rStartTab, SCTAB& rEndTab )
1711 if (rMark.GetSelectCount() > 1)
1713 rEndTab = rMark.GetLastSelected();
1714 rStartTab = rMark.GetFirstSelected();
1718 void ScModule::SetReference( const ScRange& rRef, ScDocument* pDoc,
1719 const ScMarkData* pMarkData )
1721 //TODO: Move reference dialog handling to view
1722 // Just keep function autopilot here for references to other documents
1724 // In RefDialogs we also trigger the ZoomIn, if the Ref's Start and End are different
1725 ScRange aNew = rRef;
1726 aNew.Justify(); // Always in the right direction
1728 if( nCurRefDlgId )
1730 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1731 OSL_ENSURE( pChildWnd, "NoChildWin" );
1732 if ( pChildWnd )
1734 if ( nCurRefDlgId == SID_OPENDLG_CONSOLIDATE && pMarkData )
1736 SCTAB nStartTab = aNew.aStart.Tab();
1737 SCTAB nEndTab = aNew.aEnd.Tab();
1738 lcl_MarkedTabs( *pMarkData, nStartTab, nEndTab );
1739 aNew.aStart.SetTab(nStartTab);
1740 aNew.aEnd.SetTab(nEndTab);
1743 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1744 assert(pRefDlg);
1745 if(pRefDlg)
1747 // hide the (color) selection now instead of later from LoseFocus,
1748 // don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1749 pRefDlg->HideReference( false );
1750 pRefDlg->SetReference( aNew, pDoc );
1754 else
1756 ScInputHandler* pHdl = GetInputHdl();
1757 if (pHdl)
1758 pHdl->SetReference( aNew, pDoc );
1759 else
1761 OSL_FAIL("SetReference without receiver");
1767 * Multiple selecton
1769 void ScModule::AddRefEntry()
1771 //TODO: Move reference dialog handling to view
1772 // Just keep function autopilot here for references to other documents
1773 if ( nCurRefDlgId )
1775 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1776 OSL_ENSURE( pChildWnd, "NoChildWin" );
1777 if ( pChildWnd )
1779 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1780 assert(pRefDlg);
1781 if(pRefDlg)
1783 pRefDlg->AddRefEntry();
1787 else
1789 ScInputHandler* pHdl = GetInputHdl();
1790 if (pHdl)
1791 pHdl->AddRefEntry();
1795 void ScModule::EndReference()
1797 //TODO: Move reference dialog handling to view
1798 // Just keep function autopilot here for references to other documents
1800 // We also annul the ZoomIn again in RefDialogs
1802 //FIXME: ShowRefFrame at InputHdl, if the Function AutoPilot is open?
1803 if ( nCurRefDlgId )
1805 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1806 OSL_ENSURE( pChildWnd, "NoChildWin" );
1807 if ( pChildWnd )
1809 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1810 assert(pRefDlg);
1811 if(pRefDlg)
1813 pRefDlg->SetActive();
1820 * Idle/OnlineSpelling
1822 void ScModule::AnythingChanged()
1824 sal_uLong nOldTime = aIdleTimer.GetTimeout();
1825 if ( nOldTime != SC_IDLE_MIN )
1826 aIdleTimer.SetTimeout( SC_IDLE_MIN );
1828 nIdleCount = 0;
1831 static void lcl_CheckNeedsRepaint( ScDocShell* pDocShell )
1833 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
1834 while ( pFrame )
1836 SfxViewShell* p = pFrame->GetViewShell();
1837 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
1838 if ( pViewSh )
1839 pViewSh->CheckNeedsRepaint();
1840 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
1844 IMPL_LINK_NOARG_TYPED(ScModule, IdleHandler, Timer *, void)
1846 if ( Application::AnyInput( VCL_INPUT_MOUSEANDKEYBOARD ) )
1848 aIdleTimer.Start(); // Timeout unchanged
1849 return;
1852 bool bMore = false;
1853 bool bAutoSpell = false;
1854 ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(SfxObjectShell::Current());
1856 if ( pDocSh )
1858 ScDocument& rDoc = pDocSh->GetDocument();
1859 bAutoSpell = rDoc.GetDocOptions().IsAutoSpell();
1860 if (pDocSh->IsReadOnly())
1861 bAutoSpell = false;
1863 sc::DocumentLinkManager& rLinkMgr = rDoc.GetDocLinkManager();
1864 bool bLinks = rLinkMgr.idleCheckLinks();
1865 bool bWidth = rDoc.IdleCalcTextWidth();
1867 bMore = bLinks || bWidth; // Still something at all?
1869 // While calculating a Basic formula, a paint event may have occurred,
1870 // so check the bNeedsRepaint flags for this document's views
1871 if (bWidth)
1872 lcl_CheckNeedsRepaint( pDocSh );
1875 if (bAutoSpell)
1877 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
1878 if (pViewSh)
1880 bool bSpell = pViewSh->ContinueOnlineSpelling();
1881 if (bSpell)
1883 aSpellIdle.Start();
1884 bMore = true;
1889 sal_uLong nOldTime = aIdleTimer.GetTimeout();
1890 sal_uLong nNewTime = nOldTime;
1891 if ( bMore )
1893 nNewTime = SC_IDLE_MIN;
1894 nIdleCount = 0;
1896 else
1898 // Set SC_IDLE_COUNT to initial Timeout - increase afterwards
1899 if ( nIdleCount < SC_IDLE_COUNT )
1900 ++nIdleCount;
1901 else
1903 nNewTime += SC_IDLE_STEP;
1904 if ( nNewTime > SC_IDLE_MAX )
1905 nNewTime = SC_IDLE_MAX;
1908 if ( nNewTime != nOldTime )
1909 aIdleTimer.SetTimeout( nNewTime );
1912 aIdleTimer.Start();
1915 IMPL_LINK_NOARG_TYPED(ScModule, SpellTimerHdl, Idle *, void)
1917 if ( Application::AnyInput( VclInputFlags::KEYBOARD ) )
1919 aSpellIdle.Start();
1920 return; // Later again ...
1923 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
1924 if (pViewSh)
1926 if (pViewSh->ContinueOnlineSpelling())
1927 aSpellIdle.Start();
1932 * Virtual methods for the OptionsDialog
1934 SfxItemSet* ScModule::CreateItemSet( sal_uInt16 nId )
1936 SfxItemSet* pRet = 0;
1937 if(SID_SC_EDITOPTIONS == nId)
1939 pRet = new SfxItemSet( GetPool(),
1940 // TP_CALC:
1941 SID_SCDOCOPTIONS, SID_SCDOCOPTIONS,
1942 // TP_VIEW:
1943 SID_SCVIEWOPTIONS, SID_SCVIEWOPTIONS,
1944 SID_SC_OPT_SYNCZOOM, SID_SC_OPT_SYNCZOOM,
1945 // TP_INPUT:
1946 SID_SC_INPUT_SELECTION,SID_SC_INPUT_MARK_HEADER,
1947 SID_SC_INPUT_TEXTWYSIWYG,SID_SC_INPUT_TEXTWYSIWYG,
1948 SID_SC_INPUT_REPLCELLSWARN,SID_SC_INPUT_REPLCELLSWARN,
1949 SID_SC_INPUT_LEGACY_CELL_SELECTION,SID_SC_OPT_SORT_REF_UPDATE,
1950 // TP_USERLISTS:
1951 SCITEM_USERLIST, SCITEM_USERLIST,
1952 // TP_PRINT:
1953 SID_SCPRINTOPTIONS, SID_SCPRINTOPTIONS,
1954 // TP_GRID:
1955 SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
1957 SID_ATTR_METRIC, SID_ATTR_METRIC,
1958 SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
1959 // TP_COMPATIBILITY
1960 SID_SC_OPT_KEY_BINDING_COMPAT, SID_SC_OPT_KEY_BINDING_COMPAT,
1961 // TP_DEFAULTS
1962 SID_SCDEFAULTSOPTIONS, SID_SCDEFAULTSOPTIONS,
1963 // TP_FORMULA
1964 SID_SCFORMULAOPTIONS, SID_SCFORMULAOPTIONS,
1965 0 );
1967 const ScAppOptions& rAppOpt = GetAppOptions();
1969 ScDocShell* pDocSh = PTR_CAST(ScDocShell,
1970 SfxObjectShell::Current());
1971 ScDocOptions aCalcOpt = pDocSh
1972 ? pDocSh->GetDocument().GetDocOptions()
1973 : GetDocOptions();
1975 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,
1976 SfxViewShell::Current());
1977 ScViewOptions aViewOpt = pViewSh
1978 ? pViewSh->GetViewData().GetOptions()
1979 : GetViewOptions();
1981 ScUserListItem aULItem( SCITEM_USERLIST );
1982 ScUserList* pUL = ScGlobal::GetUserList();
1984 // SfxGetpApp()->GetOptions( aSet );
1986 pRet->Put( SfxUInt16Item( SID_ATTR_METRIC,
1987 sal::static_int_cast<sal_uInt16>(rAppOpt.GetAppMetric()) ) );
1989 // TP_CALC
1990 pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP,
1991 aCalcOpt.GetTabDistance()));
1992 pRet->Put( ScTpCalcItem( SID_SCDOCOPTIONS, aCalcOpt ) );
1994 // TP_VIEW
1995 pRet->Put( ScTpViewItem( SID_SCVIEWOPTIONS, aViewOpt ) );
1996 pRet->Put( SfxBoolItem( SID_SC_OPT_SYNCZOOM, rAppOpt.GetSynchronizeZoom() ) );
1998 // TP_INPUT
1999 const ScInputOptions& rInpOpt = GetInputOptions();
2000 pRet->Put( SfxUInt16Item( SID_SC_INPUT_SELECTIONPOS,
2001 rInpOpt.GetMoveDir() ) );
2002 pRet->Put( SfxBoolItem( SID_SC_INPUT_SELECTION,
2003 rInpOpt.GetMoveSelection() ) );
2004 pRet->Put( SfxBoolItem( SID_SC_INPUT_EDITMODE,
2005 rInpOpt.GetEnterEdit() ) );
2006 pRet->Put( SfxBoolItem( SID_SC_INPUT_FMT_EXPAND,
2007 rInpOpt.GetExtendFormat() ) );
2008 pRet->Put( SfxBoolItem( SID_SC_INPUT_RANGEFINDER,
2009 rInpOpt.GetRangeFinder() ) );
2010 pRet->Put( SfxBoolItem( SID_SC_INPUT_REF_EXPAND,
2011 rInpOpt.GetExpandRefs() ) );
2012 pRet->Put( SfxBoolItem(SID_SC_OPT_SORT_REF_UPDATE, rInpOpt.GetSortRefUpdate()));
2013 pRet->Put( SfxBoolItem( SID_SC_INPUT_MARK_HEADER,
2014 rInpOpt.GetMarkHeader() ) );
2015 pRet->Put( SfxBoolItem( SID_SC_INPUT_TEXTWYSIWYG,
2016 rInpOpt.GetTextWysiwyg() ) );
2017 pRet->Put( SfxBoolItem( SID_SC_INPUT_REPLCELLSWARN,
2018 rInpOpt.GetReplaceCellsWarn() ) );
2019 pRet->Put( SfxBoolItem( SID_SC_INPUT_LEGACY_CELL_SELECTION,
2020 rInpOpt.GetLegacyCellSelection() ) );
2022 // RID_SC_TP_PRINT
2023 pRet->Put( ScTpPrintItem( SID_SCPRINTOPTIONS, GetPrintOptions() ) );
2025 // TP_GRID
2026 SvxGridItem* pSvxGridItem = aViewOpt.CreateGridItem();
2027 pRet->Put( *pSvxGridItem );
2028 delete pSvxGridItem;
2030 // TP_USERLISTS
2031 if ( pUL )
2033 aULItem.SetUserList( *pUL );
2034 pRet->Put(aULItem);
2037 // TP_COMPATIBILITY
2038 pRet->Put( SfxUInt16Item( SID_SC_OPT_KEY_BINDING_COMPAT,
2039 rAppOpt.GetKeyBindingType() ) );
2041 // TP_DEFAULTS
2042 pRet->Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS, GetDefaultsOptions() ) );
2044 // TP_FORMULA
2045 ScFormulaOptions aOptions = GetFormulaOptions();
2046 if (pDocSh)
2048 ScCalcConfig aConfig( aOptions.GetCalcConfig());
2049 aConfig.MergeDocumentSpecific( pDocSh->GetDocument().GetCalcConfig());
2050 aOptions.SetCalcConfig( aConfig);
2052 pRet->Put( ScTpFormulaItem( SID_SCFORMULAOPTIONS, aOptions ) );
2054 return pRet;
2057 void ScModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
2059 if(SID_SC_EDITOPTIONS == nId)
2061 ModifyOptions( rSet );
2065 VclPtr<SfxTabPage> ScModule::CreateTabPage( sal_uInt16 nId, vcl::Window* pParent, const SfxItemSet& rSet )
2067 VclPtr<SfxTabPage> pRet;
2068 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2069 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2070 switch(nId)
2072 case SID_SC_TP_LAYOUT:
2074 ::CreateTabPage ScTpLayoutOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_LAYOUT );
2075 if ( ScTpLayoutOptionsCreate )
2076 pRet = (*ScTpLayoutOptionsCreate) (pParent, &rSet);
2078 break;
2079 case SID_SC_TP_CONTENT:
2081 ::CreateTabPage ScTpContentOptionsCreate = pFact->GetTabPageCreatorFunc(RID_SCPAGE_CONTENT);
2082 if ( ScTpContentOptionsCreate )
2083 pRet = (*ScTpContentOptionsCreate)(pParent, &rSet);
2085 break;
2086 case SID_SC_TP_GRID: pRet = SvxGridTabPage::Create(pParent, rSet); break;
2087 case SID_SC_TP_USERLISTS:
2089 ::CreateTabPage ScTpUserListsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_USERLISTS );
2090 if ( ScTpUserListsCreate )
2091 pRet = (*ScTpUserListsCreate)( pParent, &rSet);
2093 break;
2094 case SID_SC_TP_CALC:
2096 ::CreateTabPage ScTpCalcOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_CALC );
2097 if ( ScTpCalcOptionsCreate )
2098 pRet = (*ScTpCalcOptionsCreate)(pParent, &rSet);
2100 break;
2101 case SID_SC_TP_FORMULA:
2103 ::CreateTabPage ScTpFormulaOptionsCreate = pFact->GetTabPageCreatorFunc (RID_SCPAGE_FORMULA);
2104 if (ScTpFormulaOptionsCreate)
2105 pRet = (*ScTpFormulaOptionsCreate)(pParent, &rSet);
2107 break;
2108 case SID_SC_TP_COMPATIBILITY:
2110 ::CreateTabPage ScTpCompatOptionsCreate = pFact->GetTabPageCreatorFunc (RID_SCPAGE_COMPATIBILITY);
2111 if (ScTpCompatOptionsCreate)
2112 pRet = (*ScTpCompatOptionsCreate)(pParent, &rSet);
2114 break;
2115 case SID_SC_TP_CHANGES:
2117 ::CreateTabPage ScRedlineOptionsTabPageCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_OPREDLINE );
2118 if ( ScRedlineOptionsTabPageCreate )
2119 pRet =(*ScRedlineOptionsTabPageCreate)(pParent, &rSet);
2121 break;
2122 case RID_SC_TP_PRINT:
2124 ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
2125 if ( ScTpPrintOptionsCreate )
2126 pRet = (*ScTpPrintOptionsCreate)( pParent, &rSet);
2128 break;
2129 case RID_SC_TP_DEFAULTS:
2131 ::CreateTabPage ScTpDefaultsOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_DEFAULTS );
2132 if ( ScTpDefaultsOptionsCreate )
2133 pRet = (*ScTpDefaultsOptionsCreate)( pParent, &rSet);
2135 break;
2138 OSL_ENSURE( pRet, "ScModule::CreateTabPage(): no valid ID for TabPage!" );
2140 return pRet;
2143 IMPL_LINK( ScModule, CalcFieldValueHdl, EditFieldInfo*, pInfo )
2145 //TODO: Merge with ScFieldEditEngine!
2146 if (pInfo)
2148 const SvxFieldItem& rField = pInfo->GetField();
2149 const SvxFieldData* pField = rField.GetField();
2151 if (pField && pField->ISA(SvxURLField))
2153 // URLField
2154 const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
2155 OUString aURL = pURLField->GetURL();
2157 switch ( pURLField->GetFormat() )
2159 case SVXURLFORMAT_APPDEFAULT: //TODO: Settable in the App?
2160 case SVXURLFORMAT_REPR:
2162 pInfo->SetRepresentation( pURLField->GetRepresentation() );
2164 break;
2166 case SVXURLFORMAT_URL:
2168 pInfo->SetRepresentation( aURL );
2170 break;
2173 svtools::ColorConfigEntry eEntry =
2174 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
2175 pInfo->SetTextColor( GetColorConfig().GetColorValue(eEntry).nColor );
2177 else
2179 OSL_FAIL("Unknown Field");
2180 pInfo->SetRepresentation(OUString('?'));
2184 return 0;
2187 bool ScModule::RegisterRefWindow( sal_uInt16 nSlotId, vcl::Window *pWnd )
2189 std::list<VclPtr<vcl::Window> > & rlRefWindow = m_mapRefWindow[nSlotId];
2191 if( std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd ) == rlRefWindow.end() )
2193 rlRefWindow.push_back( pWnd );
2194 return true;
2197 return false;
2200 bool ScModule::UnregisterRefWindow( sal_uInt16 nSlotId, vcl::Window *pWnd )
2202 auto iSlot = m_mapRefWindow.find( nSlotId );
2204 if( iSlot == m_mapRefWindow.end() )
2205 return false;
2207 std::list<VclPtr<vcl::Window> > & rlRefWindow = iSlot->second;
2209 auto i = std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd );
2211 if( i == rlRefWindow.end() )
2212 return false;
2214 rlRefWindow.erase( i );
2216 if( rlRefWindow.empty() )
2217 m_mapRefWindow.erase( nSlotId );
2219 return true;
2222 vcl::Window * ScModule::Find1RefWindow( sal_uInt16 nSlotId, vcl::Window *pWndAncestor )
2224 if (!pWndAncestor)
2225 return NULL;
2227 auto iSlot = m_mapRefWindow.find( nSlotId );
2229 if( iSlot == m_mapRefWindow.end() )
2230 return NULL;
2232 std::list<VclPtr<vcl::Window> > & rlRefWindow = iSlot->second;
2234 while( vcl::Window *pParent = pWndAncestor->GetParent() ) pWndAncestor = pParent;
2236 for( auto i = rlRefWindow.begin(); i!=rlRefWindow.end(); ++i )
2237 if ( pWndAncestor->IsWindowOrChild( *i, (*i)->IsSystemWindow() ) )
2238 return *i;
2240 return NULL;
2243 using namespace com::sun::star;
2245 #define LINGUPROP_AUTOSPELL "IsSpellAuto"
2247 void ScModule::GetSpellSettings( sal_uInt16& rDefLang, sal_uInt16& rCjkLang, sal_uInt16& rCtlLang,
2248 bool& rAutoSpell )
2250 // use SvtLinguConfig instead of service LinguProperties to avoid
2251 // loading the linguistic component
2252 SvtLinguConfig aConfig;
2254 SvtLinguOptions aOptions;
2255 aConfig.GetOptions( aOptions );
2257 rDefLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
2258 rCjkLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN);
2259 rCtlLang = MsLangId::resolveSystemLanguageByScriptType(aOptions.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
2260 rAutoSpell = aOptions.bIsSpellAuto;
2263 void ScModule::SetAutoSpellProperty( bool bSet )
2265 // use SvtLinguConfig instead of service LinguProperties to avoid
2266 // loading the linguistic component
2267 SvtLinguConfig aConfig;
2269 uno::Any aAny;
2270 aAny <<= bSet;
2271 aConfig.SetProperty( OUString( LINGUPROP_AUTOSPELL ), aAny );
2274 bool ScModule::HasThesaurusLanguage( sal_uInt16 nLang )
2276 if ( nLang == LANGUAGE_NONE )
2277 return false;
2279 bool bHasLang = false;
2282 uno::Reference< linguistic2::XThesaurus > xThes(LinguMgr::GetThesaurus());
2283 if ( xThes.is() )
2284 bHasLang = xThes->hasLocale( LanguageTag::convertToLocale( nLang ) );
2286 catch( uno::Exception& )
2288 OSL_FAIL("Error in Thesaurus");
2291 return bHasLang;
2294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */