Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / app / scmod.cxx
blob7dcbc9ff9f23691f162f0356573f59246a00f507
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>
65 #include "scmod.hxx"
66 #include "global.hxx"
67 #include "viewopti.hxx"
68 #include "docoptio.hxx"
69 #include "appoptio.hxx"
70 #include "defaultsoptions.hxx"
71 #include "formulaopt.hxx"
72 #include "inputopt.hxx"
73 #include "printopt.hxx"
74 #include "navicfg.hxx"
75 #include "addincfg.hxx"
76 #include "tabvwsh.hxx"
77 #include "prevwsh.hxx"
78 #include "docsh.hxx"
79 #include "drwlayer.hxx"
80 #include "uiitems.hxx"
81 #include "sc.hrc"
82 #include "cfgids.hxx"
83 #include "inputhdl.hxx"
84 #include "inputwin.hxx"
85 #include "msgpool.hxx"
86 #include "scresid.hxx"
87 #include "dwfunctr.hxx"
88 #include "formdata.hxx"
89 #include "tpprint.hxx"
90 #include "tpdefaults.hxx"
91 #include "transobj.hxx"
92 #include "detfunc.hxx"
93 #include "preview.hxx"
94 #include "dragdata.hxx"
95 #include "clipdata.hxx"
96 #include "markdata.hxx"
98 #include <svx/xmlsecctrl.hxx>
100 #define ScModule
101 #include "scslots.hxx"
103 #include "scabstdlg.hxx"
104 #include "formula/errorcodes.hxx"
105 #include "formulagroup.hxx"
107 #define SC_IDLE_MIN 150
108 #define SC_IDLE_MAX 3000
109 #define SC_IDLE_STEP 75
110 #define SC_IDLE_COUNT 50
112 static sal_uInt16 nIdleCount = 0;
114 //------------------------------------------------------------------
116 SFX_IMPL_INTERFACE( ScModule, SfxShell, ScResId(RID_APPTITLE) )
118 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER,
119 ScResId(RID_OBJECTBAR_APP) );
120 SFX_STATUSBAR_REGISTRATION( ScResId(SCCFG_STATUSBAR) ); // nur ID wichtig
123 //------------------------------------------------------------------
125 ScModule::ScModule( SfxObjectFactory* pFact ) :
126 SfxModule( SfxApplication::CreateResManager( "sc" ), false, pFact, NULL ),
127 mpDragData(new ScDragData),
128 mpClipData(new ScClipData),
129 pSelTransfer( NULL ),
130 pMessagePool( NULL ),
131 pRefInputHandler( NULL ),
132 pViewCfg( NULL ),
133 pDocCfg( NULL ),
134 pAppCfg( NULL ),
135 pDefaultsCfg( NULL ),
136 pFormulaCfg( NULL ),
137 pInputCfg( NULL ),
138 pPrintCfg( NULL ),
139 pNavipiCfg( NULL ),
140 pAddInCfg( NULL ),
141 pColorConfig( NULL ),
142 pAccessOptions( NULL ),
143 pCTLOptions( NULL ),
144 pUserOptions( NULL ),
145 pErrorHdl( NULL ),
146 pFormEditData( NULL ),
147 nCurRefDlgId( 0 ),
148 bIsWaterCan( false ),
149 bIsInEditCommand( false ),
150 bIsInExecuteDrop( false ),
151 mbIsInSharedDocLoading( false ),
152 mbIsInSharedDocSaving( false )
154 // im ctor ist der ResManager (DLL-Daten) noch nicht initialisiert!
155 SetName(OUString("StarCalc")); // for Basic
157 ResetDragObject();
158 SetClipObject( NULL, NULL );
160 // InputHandler braucht nicht mehr angelegt zu werden
162 // ErrorHandler anlegen - war in Init()
163 // zwischen OfficeApplication::Init und ScGlobal::Init
164 SvxErrorHandler::ensure();
165 pErrorHdl = new SfxErrorHandler( RID_ERRHDLSC,
166 ERRCODE_AREA_SC,
167 ERRCODE_AREA_APP2-1,
168 GetResMgr() );
170 aSpellTimer.SetTimeout(10);
171 aSpellTimer.SetTimeoutHdl( LINK( this, ScModule, SpellTimerHdl ) );
172 aIdleTimer.SetTimeout(SC_IDLE_MIN);
173 aIdleTimer.SetTimeoutHdl( LINK( this, ScModule, IdleHandler ) );
174 aIdleTimer.Start();
176 pMessagePool = new ScMessagePool;
177 pMessagePool->FreezeIdRanges();
178 SetPool( pMessagePool );
179 ScGlobal::InitTextHeight( pMessagePool );
181 StartListening( *SFX_APP() ); // for SFX_HINT_DEINITIALIZING
184 ScModule::~ScModule()
186 OSL_ENSURE( !pSelTransfer, "Selection Transfer object not deleted" );
188 // InputHandler braucht nicht mehr geloescht zu werden (gibt keinen an der App mehr)
190 SfxItemPool::Free(pMessagePool);
192 DELETEZ( pFormEditData );
194 delete mpDragData;
195 delete mpClipData;
196 delete pErrorHdl;
198 ScGlobal::Clear(); // ruft auch ScDocumentPool::DeleteVersionMaps();
200 DeleteCfg(); // wurde mal aus Exit() gerufen
203 //------------------------------------------------------------------
204 void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 )
206 if ( p == pColorConfig || p == pAccessOptions )
208 // Test if detective objects have to be updated with new colors
209 // (if the detective colors haven't been used yet, there's nothing to update)
210 if ( ScDetectiveFunc::IsColorsInitialized() )
212 const svtools::ColorConfig& rColors = GetColorConfig();
213 sal_Bool bArrows =
214 ( ScDetectiveFunc::GetArrowColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVE).nColor ||
215 ScDetectiveFunc::GetErrorColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVEERROR).nColor );
216 sal_Bool bComments =
217 ( ScDetectiveFunc::GetCommentColor() != (ColorData)rColors.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor );
218 if ( bArrows || bComments )
220 ScDetectiveFunc::InitializeColors(); // get the new colors
222 // update detective objects in all open documents
223 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
224 while ( pObjSh )
226 if ( pObjSh->Type() == TYPE(ScDocShell) )
228 ScDocShell* pDocSh = ((ScDocShell*)pObjSh);
229 if ( bArrows )
230 ScDetectiveFunc( pDocSh->GetDocument(), 0 ).UpdateAllArrowColors();
231 if ( bComments )
232 ScDetectiveFunc::UpdateAllComments( *pDocSh->GetDocument() );
234 pObjSh = SfxObjectShell::GetNext( *pObjSh );
239 // force all views to repaint, using the new options
241 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
242 while(pViewShell)
244 if ( pViewShell->ISA(ScTabViewShell) )
246 ScTabViewShell* pViewSh = (ScTabViewShell*)pViewShell;
247 pViewSh->PaintGrid();
248 pViewSh->PaintTop();
249 pViewSh->PaintLeft();
250 pViewSh->PaintExtras();
252 ScInputHandler* pHdl = pViewSh->GetInputHandler();
253 if ( pHdl )
254 pHdl->ForgetLastPattern(); // EditEngine BackgroundColor may change
256 else if ( pViewShell->ISA(ScPreviewShell) )
258 Window* pWin = pViewShell->GetWindow();
259 if (pWin)
260 pWin->Invalidate();
262 pViewShell = SfxViewShell::GetNext( *pViewShell );
265 else if ( p == pCTLOptions )
267 // for all documents: set digit language for printer, recalc output factor, update row heights
268 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
269 while ( pObjSh )
271 if ( pObjSh->Type() == TYPE(ScDocShell) )
273 ScDocShell* pDocSh = ((ScDocShell*)pObjSh);
274 OutputDevice* pPrinter = pDocSh->GetPrinter();
275 if ( pPrinter )
276 pPrinter->SetDigitLanguage( GetOptDigitLanguage() );
278 pDocSh->CalcOutputFactor();
280 SCTAB nTabCount = pDocSh->GetDocument()->GetTableCount();
281 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
282 pDocSh->AdjustRowHeight( 0, MAXROW, nTab );
284 pObjSh = SfxObjectShell::GetNext( *pObjSh );
287 // for all views (table and preview): update digit language
288 SfxViewShell* pSh = SfxViewShell::GetFirst();
289 while ( pSh )
291 if ( pSh->ISA( ScTabViewShell ) )
293 ScTabViewShell* pViewSh = (ScTabViewShell*)pSh;
295 // set ref-device for EditEngine (re-evaluates digit settings)
296 ScInputHandler* pHdl = GetInputHdl(pViewSh);
297 if (pHdl)
298 pHdl->UpdateRefDevice();
300 pViewSh->DigitLanguageChanged();
301 pViewSh->PaintGrid();
303 else if ( pSh->ISA( ScPreviewShell ) )
305 ScPreviewShell* pPreviewSh = (ScPreviewShell*)pSh;
306 ScPreview* pPreview = pPreviewSh->GetPreview();
308 pPreview->SetDigitLanguage( GetOptDigitLanguage() );
309 pPreview->Invalidate();
312 pSh = SfxViewShell::GetNext( *pSh );
317 void ScModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
319 if ( rHint.ISA(SfxSimpleHint) )
321 sal_uLong nHintId = ((SfxSimpleHint&)rHint).GetId();
322 if ( nHintId == SFX_HINT_DEINITIALIZING )
324 // ConfigItems must be removed before ConfigManager
325 DeleteCfg();
330 //------------------------------------------------------------------
332 void ScModule::DeleteCfg()
334 DELETEZ( pViewCfg ); // Speichern passiert vor Exit() automatisch
335 DELETEZ( pDocCfg );
336 DELETEZ( pAppCfg );
337 DELETEZ( pDefaultsCfg );
338 DELETEZ( pFormulaCfg );
339 DELETEZ( pInputCfg );
340 DELETEZ( pPrintCfg );
341 DELETEZ( pNavipiCfg );
342 DELETEZ( pAddInCfg );
344 if ( pColorConfig )
346 pColorConfig->RemoveListener(this);
347 DELETEZ( pColorConfig );
349 if ( pAccessOptions )
351 pAccessOptions->RemoveListener(this);
352 DELETEZ( pAccessOptions );
354 if ( pCTLOptions )
356 pCTLOptions->RemoveListener(this);
357 DELETEZ( pCTLOptions );
359 if( pUserOptions )
361 DELETEZ( pUserOptions );
365 //------------------------------------------------------------------
367 // von der Applikation verschoben:
369 //------------------------------------------------------------------
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 sal_Bool bSet;
396 const SfxPoolItem* pItem;
397 if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
398 bSet = ((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 && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
420 FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue();
421 switch( eUnit )
423 case FUNIT_MM: // nur die Einheiten, die auch im Dialog stehen
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 sal_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 sal_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 = (const SfxUInt16Item&)pReqArgs->Get(SID_PSZ_FUNCTION);
479 OSL_ENSURE(rItem.ISA(SfxUInt16Item),"falscher 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 ); // sofort
490 pBindings->Invalidate( SID_PSZ_FUNCTION );
491 pBindings->Update( SID_PSZ_FUNCTION );
492 // falls Menue gleich wieder aufgeklappt wird
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 && SFX_ITEM_SET == pReqArgs->GetItemState( GetPool().GetWhich(nSlot), sal_True, &pItem ) )
504 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
505 ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : NULL;
506 if ( pDoc )
508 LanguageType eNewLang = ((SvxLanguageItem*)pItem)->GetLanguage();
509 LanguageType eLatin, eCjk, eCtl;
510 pDoc->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 pDoc->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 ScDocument* pDoc = pDocSh->GetDocument();
608 if ( pDoc )
610 LanguageType eLatin, eCjk, eCtl;
611 pDoc->GetLanguage( eLatin, eCjk, eCtl );
612 LanguageType eLang = ( nWhich == ATTR_CJK_FONT_LANGUAGE ) ? eCjk :
613 ( ( nWhich == ATTR_CTL_FONT_LANGUAGE ) ? eCtl : eLatin );
614 rSet.Put( SvxLanguageItem( eLang, nWhich ) );
617 break;
623 void ScModule::HideDisabledSlots( SfxItemSet& rSet )
625 if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
627 SfxBindings& rBindings = pViewFrm->GetBindings();
628 SfxWhichIter aIter( rSet );
629 for( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich != 0; nWhich = aIter.NextWhich() )
631 ScViewUtil::HideDisabledSlot( rSet, rBindings, nWhich );
632 // always disable the slots
633 rSet.DisableItem( nWhich );
639 //------------------------------------------------------------------
641 void ScModule::ResetDragObject()
643 mpDragData->pCellTransfer = NULL;
644 mpDragData->pDrawTransfer = NULL;
645 mpDragData->pJumpLocalDoc = NULL;
646 mpDragData->aLinkDoc = OUString();
647 mpDragData->aLinkTable = OUString();
648 mpDragData->aLinkArea = OUString();
649 mpDragData->aJumpTarget = OUString();
650 mpDragData->aJumpText = OUString();
653 const ScDragData& ScModule::GetDragData() const
655 return *mpDragData;
658 void ScModule::SetDragObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
660 ResetDragObject();
661 mpDragData->pCellTransfer = pCellObj;
662 mpDragData->pDrawTransfer = pDrawObj;
665 void ScModule::SetDragLink(
666 const OUString& rDoc, const OUString& rTab, const OUString& rArea )
668 ResetDragObject();
669 mpDragData->aLinkDoc = rDoc;
670 mpDragData->aLinkTable = rTab;
671 mpDragData->aLinkArea = rArea;
674 void ScModule::SetDragJump(
675 ScDocument* pLocalDoc, const OUString& rTarget, const OUString& rText )
677 ResetDragObject();
679 mpDragData->pJumpLocalDoc = pLocalDoc;
680 mpDragData->aJumpTarget = rTarget;
681 mpDragData->aJumpText = rText;
684 const ScClipData& ScModule::GetClipData() const
686 return *mpClipData;
689 void ScModule::SetClipObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
691 OSL_ENSURE( !pCellObj || !pDrawObj, "SetClipObject: not allowed to set both objects" );
693 mpClipData->pCellClipboard = pCellObj;
694 mpClipData->pDrawClipboard = pDrawObj;
697 ScDocument* ScModule::GetClipDoc()
699 // called from document
701 ScTransferObj* pObj = ScTransferObj::GetOwnClipboard( NULL );
702 if (pObj)
703 return pObj->GetDocument();
705 return NULL;
708 //------------------------------------------------------------------
710 void ScModule::SetSelectionTransfer( ScSelectionTransferObj* pNew )
712 pSelTransfer = pNew;
715 //------------------------------------------------------------------
717 void ScModule::InitFormEditData()
719 pFormEditData = new ScFormEditData;
722 void ScModule::ClearFormEditData()
724 DELETEZ( pFormEditData );
727 //------------------------------------------------------------------
729 void ScModule::SetViewOptions( const ScViewOptions& rOpt )
731 if ( !pViewCfg )
732 pViewCfg = new ScViewCfg;
734 pViewCfg->SetOptions( rOpt );
737 const ScViewOptions& ScModule::GetViewOptions()
739 if ( !pViewCfg )
740 pViewCfg = new ScViewCfg;
742 return *pViewCfg;
745 void ScModule::SetDocOptions( const ScDocOptions& rOpt )
747 if ( !pDocCfg )
748 pDocCfg = new ScDocCfg;
750 pDocCfg->SetOptions( rOpt );
753 const ScDocOptions& ScModule::GetDocOptions()
755 if ( !pDocCfg )
756 pDocCfg = new ScDocCfg;
758 return *pDocCfg;
761 #ifndef LRU_MAX
762 #define LRU_MAX 10
763 #endif
765 void ScModule::InsertEntryToLRUList(sal_uInt16 nFIndex)
767 if(nFIndex != 0)
769 const ScAppOptions& rAppOpt = GetAppOptions();
770 sal_uInt16 nLRUFuncCount = std::min( rAppOpt.GetLRUFuncListCount(), (sal_uInt16)LRU_MAX );
771 sal_uInt16* pLRUListIds = rAppOpt.GetLRUFuncList();
773 sal_uInt16 aIdxList[LRU_MAX];
774 sal_uInt16 n = 0;
775 sal_Bool bFound = false;
777 while ((n < LRU_MAX) && n<nLRUFuncCount) // alte Liste abklappern
779 if (!bFound && (pLRUListIds[n]== nFIndex))
780 bFound = sal_True; // erster! Treffer
781 else if (bFound)
782 aIdxList[n ] = pLRUListIds[n]; // hinter Treffer kopieren
783 else if ((n+1) < LRU_MAX)
784 aIdxList[n+1] = pLRUListIds[n]; // vor Treffer verschieben
785 n++;
787 if (!bFound && (n < LRU_MAX)) // Eintrag nicht gefunden?
788 n++; // einen mehr
789 aIdxList[0] = nFIndex; // Current on Top
791 ScAppOptions aNewOpts(rAppOpt); // an App melden
792 aNewOpts.SetLRUFuncList(aIdxList, n);
793 SetAppOptions(aNewOpts);
795 RecentFunctionsChanged();
799 void ScModule::RecentFunctionsChanged()
801 // update function list window
802 sal_uInt16 nFuncListID = ScFunctionChildWindow::GetChildWindowId();
804 //! notify all views
805 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
806 if ( pViewFrm && pViewFrm->HasChildWindow(nFuncListID) )
808 ScFunctionChildWindow* pWnd =(ScFunctionChildWindow*)pViewFrm->GetChildWindow( nFuncListID );
810 ScFunctionDockWin* pFuncList=(ScFunctionDockWin*)pWnd->GetWindow();
812 pFuncList->InitLRUList();
816 void ScModule::SetAppOptions( const ScAppOptions& rOpt )
818 if ( !pAppCfg )
819 pAppCfg = new ScAppCfg;
821 pAppCfg->SetOptions( rOpt );
824 void global_InitAppOptions()
826 SC_MOD()->GetAppOptions();
829 const ScAppOptions& ScModule::GetAppOptions()
831 if ( !pAppCfg )
832 pAppCfg = new ScAppCfg;
834 return *pAppCfg;
837 void ScModule::SetDefaultsOptions( const ScDefaultsOptions& rOpt )
839 if ( !pDefaultsCfg )
840 pDefaultsCfg = new ScDefaultsCfg;
842 pDefaultsCfg->SetOptions( rOpt );
845 const ScDefaultsOptions& ScModule::GetDefaultsOptions()
847 if ( !pDefaultsCfg )
848 pDefaultsCfg = new ScDefaultsCfg;
850 return *pDefaultsCfg;
853 void ScModule::SetFormulaOptions( const ScFormulaOptions& rOpt )
855 if ( !pFormulaCfg )
856 pFormulaCfg = new ScFormulaCfg;
858 pFormulaCfg->SetOptions( rOpt );
861 const ScFormulaOptions& ScModule::GetFormulaOptions()
863 if ( !pFormulaCfg )
864 pFormulaCfg = new ScFormulaCfg;
866 return *pFormulaCfg;
869 void ScModule::SetInputOptions( const ScInputOptions& rOpt )
871 if ( !pInputCfg )
872 pInputCfg = new ScInputCfg;
874 pInputCfg->SetOptions( rOpt );
877 const ScInputOptions& ScModule::GetInputOptions()
879 if ( !pInputCfg )
880 pInputCfg = new ScInputCfg;
882 return *pInputCfg;
885 void ScModule::SetPrintOptions( const ScPrintOptions& rOpt )
887 if ( !pPrintCfg )
888 pPrintCfg = new ScPrintCfg;
890 pPrintCfg->SetOptions( rOpt );
893 const ScPrintOptions& ScModule::GetPrintOptions()
895 if ( !pPrintCfg )
896 pPrintCfg = new ScPrintCfg;
898 return *pPrintCfg;
901 ScNavipiCfg& ScModule::GetNavipiCfg()
903 if ( !pNavipiCfg )
904 pNavipiCfg = new ScNavipiCfg;
906 return *pNavipiCfg;
909 ScAddInCfg& ScModule::GetAddInCfg()
911 if ( !pAddInCfg )
912 pAddInCfg = new ScAddInCfg;
914 return *pAddInCfg;
917 svtools::ColorConfig& ScModule::GetColorConfig()
919 if ( !pColorConfig )
921 pColorConfig = new svtools::ColorConfig;
922 pColorConfig->AddListener(this);
925 return *pColorConfig;
928 SvtAccessibilityOptions& ScModule::GetAccessOptions()
930 if ( !pAccessOptions )
932 pAccessOptions = new SvtAccessibilityOptions;
933 pAccessOptions->AddListener(this);
936 return *pAccessOptions;
939 SvtCTLOptions& ScModule::GetCTLOptions()
941 if ( !pCTLOptions )
943 pCTLOptions = new SvtCTLOptions;
944 pCTLOptions->AddListener(this);
947 return *pCTLOptions;
950 SvtUserOptions& ScModule::GetUserOptions()
952 if( !pUserOptions )
954 pUserOptions = new SvtUserOptions;
956 return *pUserOptions;
959 sal_uInt16 ScModule::GetOptDigitLanguage()
961 SvtCTLOptions::TextNumerals eNumerals = GetCTLOptions().GetCTLTextNumerals();
962 return ( eNumerals == SvtCTLOptions::NUMERALS_ARABIC ) ? LANGUAGE_ENGLISH_US :
963 ( eNumerals == SvtCTLOptions::NUMERALS_HINDI) ? LANGUAGE_ARABIC_SAUDI_ARABIA :
964 LANGUAGE_SYSTEM;
967 //------------------------------------------------------------------
969 // Optionen
971 //------------------------------------------------------------------
974 // ModifyOptions - Items aus Calc-Options-Dialog
975 // und SID_AUTOSPELL_CHECK
978 void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
980 sal_uInt16 nOldSpellLang, nOldCjkLang, nOldCtlLang;
981 sal_Bool bOldAutoSpell;
982 GetSpellSettings( nOldSpellLang, nOldCjkLang, nOldCtlLang, bOldAutoSpell );
984 if (!pAppCfg)
985 GetAppOptions();
986 OSL_ENSURE( pAppCfg, "AppOptions not initialised :-(" );
988 if (!pInputCfg)
989 GetInputOptions();
990 OSL_ENSURE( pInputCfg, "InputOptions not initialised :-(" );
992 //--------------------------------------------------------------
994 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
995 SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : NULL;
997 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
998 ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
999 ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : NULL;
1000 const SfxPoolItem* pItem = NULL;
1001 bool bRepaint = false;
1002 bool bUpdateMarks = false;
1003 bool bUpdateRefDev = false;
1004 bool bCalcAll = false;
1005 bool bSaveAppOptions = false;
1006 bool bSaveInputOptions = false;
1007 bool bCompileErrorCells = false;
1009 //--------------------------------------------------------------------------
1011 // SFX_APP()->SetOptions( rOptSet );
1013 // Linguistik nicht mehr
1015 if (rOptSet.HasItem(SID_ATTR_METRIC, &pItem))
1017 PutItem( *pItem );
1018 pAppCfg->SetAppMetric( (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue() );
1019 bSaveAppOptions = sal_True;
1022 if (rOptSet.HasItem(SCITEM_USERLIST, &pItem))
1024 ScGlobal::SetUserList( ((const ScUserListItem*)pItem)->GetUserList() );
1025 bSaveAppOptions = sal_True;
1028 if (rOptSet.HasItem(SID_SC_OPT_SYNCZOOM, &pItem))
1030 pAppCfg->SetSynchronizeZoom( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1031 bSaveAppOptions = sal_True;
1034 if (rOptSet.HasItem(SID_SC_OPT_KEY_BINDING_COMPAT, &pItem))
1036 sal_uInt16 nVal = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1037 ScOptionsUtil::KeyBindingType eOld = pAppCfg->GetKeyBindingType();
1038 ScOptionsUtil::KeyBindingType eNew = static_cast<ScOptionsUtil::KeyBindingType>(nVal);
1039 if (eOld != eNew)
1041 pAppCfg->SetKeyBindingType(eNew);
1042 bSaveAppOptions = true;
1043 pDocSh->ResetKeyBindings(eNew);
1047 //============================================
1048 // DefaultsOptions
1049 //============================================
1051 if (rOptSet.HasItem(SID_SCDEFAULTSOPTIONS, &pItem))
1053 const ScDefaultsOptions& rOpt = ((const ScTpDefaultsItem*)pItem)->GetDefaultsOptions();
1054 SetDefaultsOptions( rOpt );
1057 //============================================
1058 // FormulaOptions
1059 //============================================
1061 if (rOptSet.HasItem(SID_SCFORMULAOPTIONS, &pItem))
1063 const ScFormulaOptions& rOpt = ((const ScTpFormulaItem*)pItem)->GetFormulaOptions();
1065 if (!pFormulaCfg || (*pFormulaCfg != rOpt))
1066 // Formula options have changed. Repaint the column headers.
1067 bRepaint = true;
1069 if (pFormulaCfg && pFormulaCfg->GetUseEnglishFuncName() != rOpt.GetUseEnglishFuncName())
1071 // Re-compile formula cells with error as the error may have been
1072 // caused by unresolved function names.
1073 bCompileErrorCells = true;
1076 SetFormulaOptions( rOpt );
1078 if ( pDocSh )
1080 pDocSh->SetFormulaOptions( rOpt );
1081 pDocSh->SetDocumentModified();
1085 //============================================
1086 // ViewOptions
1087 //============================================
1089 if (rOptSet.HasItem(SID_SCVIEWOPTIONS, &pItem))
1091 const ScViewOptions& rNewOpt = ((const ScTpViewItem*)pItem)->GetViewOptions();
1093 if ( pViewSh )
1095 ScViewData* pViewData = pViewSh->GetViewData();
1096 const ScViewOptions& rOldOpt = pViewData->GetOptions();
1098 sal_Bool bAnchorList = ( rOldOpt.GetOption( VOPT_ANCHOR ) !=
1099 rNewOpt.GetOption( VOPT_ANCHOR ) );
1101 if ( rOldOpt != rNewOpt )
1103 pViewData->SetOptions( rNewOpt ); // veraendert rOldOpt
1104 pViewData->GetDocument()->SetViewOptions( rNewOpt );
1105 pDocSh->SetDocumentModified();
1106 bRepaint = sal_True;
1108 if ( bAnchorList )
1109 pViewSh->UpdateAnchorHandles();
1111 SetViewOptions( rNewOpt );
1112 if (pBindings)
1114 pBindings->Invalidate(SID_HELPLINES_MOVE);
1115 pBindings->Invalidate(SID_SCGRIDSHOW);
1119 //============================================
1120 // GridOptions, Auswertung nach ViewOptions,
1121 // da GridOptions Member der ViewOptions ist!
1122 //============================================
1124 if ( rOptSet.HasItem(SID_ATTR_GRID_OPTIONS,&pItem) )
1126 ScGridOptions aNewGridOpt( (const SvxOptionsGrid&)((const SvxGridItem&)*pItem) );
1128 if ( pViewSh )
1130 ScViewData* pViewData = pViewSh->GetViewData();
1131 ScViewOptions aNewViewOpt( pViewData->GetOptions() );
1132 const ScGridOptions& rOldGridOpt = aNewViewOpt.GetGridOptions();
1134 if ( rOldGridOpt != aNewGridOpt )
1136 aNewViewOpt.SetGridOptions( aNewGridOpt );
1137 pViewData->SetOptions( aNewViewOpt );
1138 pViewData->GetDocument()->SetViewOptions( aNewViewOpt );
1139 pDocSh->SetDocumentModified();
1140 bRepaint = sal_True;
1143 ScViewOptions aNewViewOpt ( GetViewOptions() );
1144 aNewViewOpt.SetGridOptions( aNewGridOpt );
1145 SetViewOptions( aNewViewOpt );
1146 if (pBindings)
1148 pBindings->Invalidate(SID_GRID_VISIBLE);
1149 pBindings->Invalidate(SID_GRID_USE);
1154 //============================================
1155 // DocOptions
1156 //============================================
1158 if ( rOptSet.HasItem(SID_SCDOCOPTIONS,&pItem) )
1160 const ScDocOptions& rNewOpt = ((const ScTpCalcItem*)pItem)->GetDocOptions();
1162 if ( pDoc )
1164 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1166 bRepaint = ( bRepaint || ( rOldOpt != rNewOpt ) );
1167 bCalcAll = bRepaint &&
1168 ( rOldOpt.IsIter() != rNewOpt.IsIter()
1169 || rOldOpt.GetIterCount() != rNewOpt.GetIterCount()
1170 || rOldOpt.GetIterEps() != rNewOpt.GetIterEps()
1171 || rOldOpt.IsIgnoreCase() != rNewOpt.IsIgnoreCase()
1172 || rOldOpt.IsCalcAsShown() != rNewOpt.IsCalcAsShown()
1173 || (rNewOpt.IsCalcAsShown() &&
1174 rOldOpt.GetStdPrecision() != rNewOpt.GetStdPrecision())
1175 || rOldOpt.IsMatchWholeCell() != rNewOpt.IsMatchWholeCell()
1176 || rOldOpt.GetYear2000() != rNewOpt.GetYear2000()
1177 || rOldOpt.IsFormulaRegexEnabled() != rNewOpt.IsFormulaRegexEnabled()
1179 pDoc->SetDocOptions( rNewOpt );
1180 pDocSh->SetDocumentModified();
1182 SetDocOptions( rNewOpt );
1185 // nach den eigentlichen DocOptions auch noch die TabDistance setzen
1186 if ( rOptSet.HasItem(SID_ATTR_DEFTABSTOP,&pItem) )
1188 sal_uInt16 nTabDist = ((SfxUInt16Item*)pItem)->GetValue();
1189 ScDocOptions aOpt(GetDocOptions());
1190 aOpt.SetTabDistance(nTabDist);
1191 SetDocOptions( aOpt );
1193 if ( pDoc )
1195 ScDocOptions aDocOpt(pDoc->GetDocOptions());
1196 aDocOpt.SetTabDistance(nTabDist);
1197 pDoc->SetDocOptions( aDocOpt );
1198 pDocSh->SetDocumentModified();
1199 if(pDoc->GetDrawLayer())
1200 pDoc->GetDrawLayer()->SetDefaultTabulator(nTabDist);
1204 // AutoSpell nach den Doc-Options (weil Member)
1206 if ( rOptSet.HasItem(SID_AUTOSPELL_CHECK,&pItem) ) // an Doc-Options
1208 sal_Bool bDoAutoSpell = ((const SfxBoolItem*)pItem)->GetValue();
1210 if (pDoc)
1212 ScDocOptions aNewOpt = pDoc->GetDocOptions();
1213 if ( aNewOpt.IsAutoSpell() != bDoAutoSpell )
1215 aNewOpt.SetAutoSpell( bDoAutoSpell );
1216 pDoc->SetDocOptions( aNewOpt );
1218 if (pViewSh)
1219 pViewSh->EnableAutoSpell(bDoAutoSpell);
1221 bRepaint = true; // weil HideAutoSpell evtl. ungueltig
1222 //! alle Views painten ???
1226 if ( bOldAutoSpell != bDoAutoSpell )
1227 SetAutoSpellProperty( bDoAutoSpell );
1228 if ( pDocSh )
1229 pDocSh->PostPaintGridAll(); // wegen Markierungen
1230 ScInputHandler* pInputHandler = GetInputHdl();
1231 if ( pInputHandler )
1232 pInputHandler->UpdateSpellSettings(); // EditEngine-Flags
1233 if ( pViewSh )
1234 pViewSh->UpdateDrawTextOutliner(); // EditEngine-Flags
1236 if (pBindings)
1237 pBindings->Invalidate( SID_AUTOSPELL_CHECK );
1240 //============================================
1241 // InputOptions
1242 //============================================
1244 if ( rOptSet.HasItem(SID_SC_INPUT_SELECTIONPOS,&pItem) )
1246 pInputCfg->SetMoveDir( ((const SfxUInt16Item*)pItem)->GetValue() );
1247 bSaveInputOptions = sal_True;
1249 if ( rOptSet.HasItem(SID_SC_INPUT_SELECTION,&pItem) )
1251 pInputCfg->SetMoveSelection( ((const SfxBoolItem*)pItem)->GetValue() );
1252 bSaveInputOptions = sal_True;
1254 if ( rOptSet.HasItem(SID_SC_INPUT_EDITMODE,&pItem) )
1256 pInputCfg->SetEnterEdit( ((const SfxBoolItem*)pItem)->GetValue() );
1257 bSaveInputOptions = sal_True;
1259 if ( rOptSet.HasItem(SID_SC_INPUT_FMT_EXPAND,&pItem) )
1261 pInputCfg->SetExtendFormat( ((const SfxBoolItem*)pItem)->GetValue() );
1262 bSaveInputOptions = sal_True;
1264 if ( rOptSet.HasItem(SID_SC_INPUT_RANGEFINDER,&pItem) )
1266 pInputCfg->SetRangeFinder( ((const SfxBoolItem*)pItem)->GetValue() );
1267 bSaveInputOptions = sal_True;
1269 if ( rOptSet.HasItem(SID_SC_INPUT_REF_EXPAND,&pItem) )
1271 pInputCfg->SetExpandRefs( ((const SfxBoolItem*)pItem)->GetValue() );
1272 bSaveInputOptions = sal_True;
1274 if ( rOptSet.HasItem(SID_SC_INPUT_MARK_HEADER,&pItem) )
1276 pInputCfg->SetMarkHeader( ((const SfxBoolItem*)pItem)->GetValue() );
1277 bSaveInputOptions = sal_True;
1278 bUpdateMarks = sal_True;
1280 if ( rOptSet.HasItem(SID_SC_INPUT_TEXTWYSIWYG,&pItem) )
1282 sal_Bool bNew = ((const SfxBoolItem*)pItem)->GetValue();
1283 if ( bNew != pInputCfg->GetTextWysiwyg() )
1285 pInputCfg->SetTextWysiwyg( bNew );
1286 bSaveInputOptions = sal_True;
1287 bUpdateRefDev = sal_True;
1290 if( rOptSet.HasItem( SID_SC_INPUT_REPLCELLSWARN, &pItem ) )
1292 pInputCfg->SetReplaceCellsWarn( ((const SfxBoolItem*)pItem)->GetValue() );
1293 bSaveInputOptions = sal_True;
1296 if( rOptSet.HasItem( SID_SC_INPUT_LEGACY_CELL_SELECTION, &pItem ) )
1298 pInputCfg->SetLegacyCellSelection( ((const SfxBoolItem*)pItem)->GetValue() );
1299 bSaveInputOptions = sal_True;
1302 //============================================
1303 // PrintOptions
1304 //============================================
1306 if ( rOptSet.HasItem(SID_SCPRINTOPTIONS,&pItem) )
1308 const ScPrintOptions& rNewOpt = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
1309 SetPrintOptions( rNewOpt );
1311 // broadcast causes all previews to recalc page numbers
1312 SFX_APP()->Broadcast( SfxSimpleHint( SID_SCPRINTOPTIONS ) );
1315 //----------------------------------------------------------
1317 if ( bSaveAppOptions )
1318 pAppCfg->OptionsChanged();
1320 if ( bSaveInputOptions )
1321 pInputCfg->OptionsChanged();
1323 // Neuberechnung anstossen?
1325 if (pDoc && bCompileErrorCells)
1327 // Re-compile cells with name error, and recalc if at least one cell
1328 // has been re-compiled. In the future we may want to find a way to
1329 // recalc only those that are affected.
1330 if (pDoc->CompileErrorCells(ScErrorCodes::errNoName))
1331 bCalcAll = true;
1334 if ( pDoc && bCalcAll )
1336 WaitObject aWait( pDocSh->GetActiveDialogParent() );
1337 pDoc->CalcAll();
1338 if ( pViewSh )
1339 pViewSh->UpdateCharts( sal_True );
1340 else
1341 ScDBFunc::DoUpdateCharts( ScAddress(), pDoc, sal_True );
1342 if (pBindings)
1343 pBindings->Invalidate( SID_ATTR_SIZE ); //SvxPosSize-StatusControl-Update
1346 if ( pViewSh && bUpdateMarks )
1347 pViewSh->UpdateAutoFillMark();
1349 // View neuzeichnen?
1351 if ( pViewSh && bRepaint )
1353 pViewSh->UpdateFixPos();
1354 pViewSh->PaintGrid();
1355 pViewSh->PaintTop();
1356 pViewSh->PaintLeft();
1357 pViewSh->PaintExtras();
1358 pViewSh->InvalidateBorder();
1359 if (pBindings)
1361 pBindings->Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
1362 pBindings->Invalidate( FID_TOGGLESYNTAX );
1366 // update ref device (for all documents)
1368 if ( bUpdateRefDev )
1370 // for all documents: recalc output factor, update row heights
1371 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
1372 while ( pObjSh )
1374 if ( pObjSh->Type() == TYPE(ScDocShell) )
1376 ScDocShell* pOneDocSh = ((ScDocShell*)pObjSh);
1377 pOneDocSh->CalcOutputFactor();
1378 SCTAB nTabCount = pOneDocSh->GetDocument()->GetTableCount();
1379 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1380 pOneDocSh->AdjustRowHeight( 0, MAXROW, nTab );
1382 pObjSh = SfxObjectShell::GetNext( *pObjSh );
1385 // for all (tab-) views:
1386 TypeId aScType = TYPE(ScTabViewShell);
1387 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
1388 while ( pSh )
1390 ScTabViewShell* pOneViewSh = (ScTabViewShell*)pSh;
1392 // set ref-device for EditEngine
1393 ScInputHandler* pHdl = GetInputHdl(pOneViewSh);
1394 if (pHdl)
1395 pHdl->UpdateRefDevice();
1397 // update view scale
1398 ScViewData* pViewData = pOneViewSh->GetViewData();
1399 pOneViewSh->SetZoom( pViewData->GetZoomX(), pViewData->GetZoomY(), false );
1401 // repaint
1402 pOneViewSh->PaintGrid();
1403 pOneViewSh->PaintTop();
1404 pOneViewSh->PaintLeft();
1406 pSh = SfxViewShell::GetNext( *pSh, &aScType );
1411 //------------------------------------------------------------------
1413 // Input-Handler
1415 //------------------------------------------------------------------
1417 ScInputHandler* ScModule::GetInputHdl( ScTabViewShell* pViewSh, sal_Bool bUseRef )
1419 if ( pRefInputHandler && bUseRef )
1420 return pRefInputHandler;
1422 ScInputHandler* pHdl = NULL;
1423 if ( !pViewSh )
1425 // in case a UIActive embedded object has no ViewShell ( UNO component )
1426 // the own calc view shell will be set as current, but no handling should happen
1428 ScTabViewShell* pCurViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
1429 if ( pCurViewSh && !pCurViewSh->GetUIActiveClient() )
1430 pViewSh = pCurViewSh;
1433 if ( pViewSh )
1434 pHdl = pViewSh->GetInputHandler(); // Viewshell hat jetzt immer einen
1436 // wenn keine ViewShell uebergeben oder aktiv, kann NULL herauskommen
1437 OSL_ENSURE( pHdl || !pViewSh, "GetInputHdl: kein InputHandler gefunden" );
1438 return pHdl;
1441 void ScModule::ViewShellChanged()
1443 ScInputHandler* pHdl = GetInputHdl();
1444 ScTabViewShell* pShell = ScTabViewShell::GetActiveViewShell();
1445 if ( pShell && pHdl )
1446 pShell->UpdateInputHandler();
1449 void ScModule::SetInputMode( ScInputMode eMode )
1451 ScInputHandler* pHdl = GetInputHdl();
1452 if (pHdl)
1453 pHdl->SetMode( eMode );
1456 sal_Bool ScModule::IsEditMode()
1458 ScInputHandler* pHdl = GetInputHdl();
1459 return pHdl && pHdl->IsEditMode();
1462 sal_Bool ScModule::IsInputMode()
1464 ScInputHandler* pHdl = GetInputHdl();
1465 return pHdl && pHdl->IsInputMode();
1468 sal_Bool ScModule::InputKeyEvent( const KeyEvent& rKEvt, sal_Bool bStartEdit )
1470 ScInputHandler* pHdl = GetInputHdl();
1471 return ( pHdl ? pHdl->KeyInput( rKEvt, bStartEdit ) : false );
1474 void ScModule::InputEnterHandler( sal_uInt8 nBlockMode )
1476 if ( !SFX_APP()->IsDowning() ) // nicht beim Programmende
1478 ScInputHandler* pHdl = GetInputHdl();
1479 if (pHdl)
1480 pHdl->EnterHandler( nBlockMode );
1484 void ScModule::InputCancelHandler()
1486 ScInputHandler* pHdl = GetInputHdl();
1487 if (pHdl)
1488 pHdl->CancelHandler();
1491 void ScModule::InputSelection( EditView* pView )
1493 ScInputHandler* pHdl = GetInputHdl();
1494 if (pHdl)
1495 pHdl->InputSelection( pView );
1498 void ScModule::InputChanged( EditView* pView )
1500 ScInputHandler* pHdl = GetInputHdl();
1501 if (pHdl)
1502 pHdl->InputChanged( pView );
1505 void ScModule::ViewShellGone( ScTabViewShell* pViewSh )
1507 ScInputHandler* pHdl = GetInputHdl();
1508 if (pHdl)
1509 pHdl->ViewShellGone( pViewSh );
1512 void ScModule::SetRefInputHdl( ScInputHandler* pNew )
1514 pRefInputHandler = pNew;
1517 ScInputHandler* ScModule::GetRefInputHdl()
1519 return pRefInputHandler;
1522 //------------------------------------------------------------------------
1523 // Olk's Krempel:
1525 void ScModule::InputGetSelection( xub_StrLen& rStart, xub_StrLen& rEnd )
1527 ScInputHandler* pHdl = GetInputHdl();
1528 if (pHdl)
1529 pHdl->InputGetSelection( rStart, rEnd );
1532 void ScModule::InputSetSelection( xub_StrLen nStart, xub_StrLen nEnd )
1534 ScInputHandler* pHdl = GetInputHdl();
1535 if (pHdl)
1536 pHdl->InputSetSelection( nStart, nEnd );
1539 void ScModule::InputReplaceSelection( const OUString& rStr )
1541 ScInputHandler* pHdl = GetInputHdl();
1542 if (pHdl)
1543 pHdl->InputReplaceSelection( rStr );
1546 void ScModule::InputTurnOffWinEngine()
1548 ScInputHandler* pHdl = GetInputHdl();
1549 if (pHdl)
1550 pHdl->InputTurnOffWinEngine();
1553 OUString ScModule::InputGetFormulaStr()
1555 ScInputHandler* pHdl = GetInputHdl();
1556 OUString aStr;
1557 if ( pHdl )
1558 aStr = pHdl->GetFormString();
1559 return aStr;
1562 void ScModule::ActivateInputWindow( const OUString* pStrFormula, sal_Bool bMatrix )
1564 ScInputHandler* pHdl = GetInputHdl();
1565 if ( pHdl )
1567 ScInputWindow* pWin = pHdl->GetInputWindow();
1568 if ( pStrFormula )
1570 // Formel uebernehmen
1571 if ( pWin )
1573 pWin->SetFuncString( *pStrFormula, false );
1574 // SetSumAssignMode wegen sal_False nicht noetig
1576 sal_uInt8 nMode = bMatrix ? SC_ENTER_MATRIX : SC_ENTER_NORMAL;
1577 pHdl->EnterHandler( nMode );
1579 // ohne Invalidate bleibt die Selektion stehen, wenn die Formel unveraendert ist
1580 if (pWin)
1581 pWin->TextInvalidate();
1583 else
1585 // Abbrechen
1586 if ( pWin )
1588 pWin->SetFuncString( EMPTY_OUSTRING, false );
1589 // SetSumAssignMode wegen sal_False nicht noetig
1591 pHdl->CancelHandler();
1596 //------------------------------------------------------------------
1598 // Referenz - Dialoge
1600 //------------------------------------------------------------------
1602 void ScModule::SetRefDialog( sal_uInt16 nId, sal_Bool bVis, SfxViewFrame* pViewFrm )
1604 //! move reference dialog handling to view
1605 //! (only keep function autopilot here for references to other documents)
1607 if(nCurRefDlgId==0 || (nId==nCurRefDlgId && !bVis))
1609 if ( !pViewFrm )
1610 pViewFrm = SfxViewFrame::Current();
1612 // bindings update causes problems with update of stylist if
1613 // current style family has changed
1614 //if ( pViewFrm )
1615 // pViewFrm->GetBindings().Update(); // to avoid trouble in LockDispatcher
1617 nCurRefDlgId = bVis ? nId : 0 ; // before SetChildWindow
1619 if ( pViewFrm )
1621 // store the dialog id also in the view shell
1622 SfxViewShell* pViewSh = pViewFrm->GetViewShell();
1623 if ( pViewSh && pViewSh->ISA( ScTabViewShell ) )
1624 ((ScTabViewShell*)pViewSh)->SetCurRefDlgId( nCurRefDlgId );
1625 else
1627 // no ScTabViewShell - possible for example from a Basic macro
1628 bVis = false;
1629 nCurRefDlgId = 0; // don't set nCurRefDlgId if no dialog is created
1632 pViewFrm->SetChildWindow( nId, bVis );
1635 SfxApplication* pSfxApp = SFX_APP();
1636 pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) );
1640 static SfxChildWindow* lcl_GetChildWinFromAnyView( sal_uInt16 nId )
1642 // first try the current view
1644 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1645 // #i46999# current view frame can be null (for example, when closing help)
1646 SfxChildWindow* pChildWnd = pViewFrm ? pViewFrm->GetChildWindow( nId ) : NULL;
1647 if ( pChildWnd )
1648 return pChildWnd; // found in the current view
1650 // if not found there, get the child window from any open view
1651 // it can be open only in one view because nCurRefDlgId is global
1653 pViewFrm = SfxViewFrame::GetFirst();
1654 while ( pViewFrm )
1656 pChildWnd = pViewFrm->GetChildWindow( nId );
1657 if ( pChildWnd )
1658 return pChildWnd; // found in any view
1660 pViewFrm = SfxViewFrame::GetNext( *pViewFrm );
1663 return NULL; // none found
1666 sal_Bool ScModule::IsModalMode(SfxObjectShell* pDocSh)
1668 //! move reference dialog handling to view
1669 //! (only keep function autopilot here for references to other documents)
1671 sal_Bool bIsModal = false;
1673 if ( nCurRefDlgId )
1675 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1676 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1677 if ( pChildWnd )
1679 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1680 bIsModal = pChildWnd->IsVisible() &&
1681 !( pRefDlg->IsRefInputMode() && pRefDlg->IsDocAllowed(pDocSh) );
1683 else if(pModalDlg)
1685 bIsModal = pModalDlg->IsVisible() && !(pModalDlg->IsRefInputMode() && pModalDlg->IsDocAllowed(pDocSh) );
1687 else
1689 // in 592 and above, the dialog isn't visible in other views
1690 // if the dialog is open but can't be accessed, disable input
1692 bIsModal = sal_True;
1695 // pChildWnd kann 0 sein, wenn der Dialog nach dem Umschalten
1696 // von einer anderen Shell noch nicht erzeugt wurde (z.B. in GetFocus)
1698 else if (pDocSh)
1700 ScInputHandler* pHdl = GetInputHdl();
1701 if ( pHdl )
1702 bIsModal = pHdl->IsModalMode(pDocSh);
1705 return bIsModal;
1708 sal_Bool ScModule::IsTableLocked()
1710 //! move reference dialog handling to view
1711 //! (only keep function autopilot here for references to other documents)
1713 sal_Bool bLocked = false;
1715 // bisher nur bei ScAnyRefDlg
1717 if ( nCurRefDlgId )
1719 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1720 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1721 if ( pChildWnd )
1722 bLocked = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow())->IsTableLocked();
1723 else if( pModalDlg )
1724 bLocked = pModalDlg->IsTableLocked();
1725 else
1726 bLocked = sal_True; // for other views, see IsModalMode
1729 return bLocked;
1732 sal_Bool ScModule::IsRefDialogOpen()
1734 //! move reference dialog handling to view
1735 //! (only keep function autopilot here for references to other documents)
1737 sal_Bool bIsOpen = false;
1739 if ( nCurRefDlgId )
1741 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1742 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1743 if ( pChildWnd )
1744 bIsOpen = pChildWnd->IsVisible();
1745 else if(pModalDlg)
1746 bIsOpen = pModalDlg->IsVisible();
1747 else
1748 bIsOpen = sal_True; // for other views, see IsModalMode
1751 return bIsOpen;
1754 sal_Bool ScModule::IsFormulaMode()
1756 //! move reference dialog handling to view
1757 //! (only keep function autopilot here for references to other documents)
1759 sal_Bool bIsFormula = false;
1761 if ( nCurRefDlgId )
1763 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1764 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1765 if ( pChildWnd )
1767 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1768 bIsFormula = pChildWnd->IsVisible() && pRefDlg->IsRefInputMode();
1770 else if(pModalDlg)
1772 bIsFormula = pModalDlg->IsVisible() && pModalDlg->IsRefInputMode();
1774 else
1775 bIsFormula = true;
1777 else
1779 ScInputHandler* pHdl = GetInputHdl();
1780 if ( pHdl )
1781 bIsFormula = pHdl->IsFormulaMode();
1784 if (bIsInEditCommand)
1785 bIsFormula = sal_True;
1787 return bIsFormula;
1790 static void lcl_MarkedTabs( const ScMarkData& rMark, SCTAB& rStartTab, SCTAB& rEndTab )
1792 if (rMark.GetSelectCount() > 1)
1794 rEndTab = rMark.GetLastSelected();
1795 rStartTab = rMark.GetFirstSelected();
1799 void ScModule::SetReference( const ScRange& rRef, ScDocument* pDoc,
1800 const ScMarkData* pMarkData )
1802 //! move reference dialog handling to view
1803 //! (only keep function autopilot here for references to other documents)
1805 // in Ref-Dialogen wird hiermit auch das Zoom-In ausgeloest,
1806 // wenn Start und Ende der Ref unterschiedlich sind
1808 ScRange aNew = rRef;
1809 aNew.Justify(); // immer "richtig herum"
1811 if( nCurRefDlgId )
1813 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1814 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1815 OSL_ENSURE( pChildWnd || pModalDlg, "NoChildWin" );
1816 if ( pChildWnd )
1818 if ( nCurRefDlgId == SID_OPENDLG_CONSOLIDATE && pMarkData )
1820 SCTAB nStartTab = aNew.aStart.Tab();
1821 SCTAB nEndTab = aNew.aEnd.Tab();
1822 lcl_MarkedTabs( *pMarkData, nStartTab, nEndTab );
1823 aNew.aStart.SetTab(nStartTab);
1824 aNew.aEnd.SetTab(nEndTab);
1827 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1829 // hide the (color) selection now instead of later from LoseFocus,
1830 // don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1831 pRefDlg->HideReference( false );
1832 pRefDlg->SetReference( aNew, pDoc );
1834 else if(pModalDlg)
1836 // hide the (color) selection now instead of later from LoseFocus,
1837 // don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1838 pModalDlg->HideReference( false );
1839 pModalDlg->SetReference( aNew, pDoc );
1842 else
1844 ScInputHandler* pHdl = GetInputHdl();
1845 if (pHdl)
1846 pHdl->SetReference( aNew, pDoc );
1847 else
1849 OSL_FAIL("SetReference ohne Empfaenger");
1854 void ScModule::AddRefEntry() // "Mehrfachselektion"
1856 //! move reference dialog handling to view
1857 //! (only keep function autopilot here for references to other documents)
1859 if ( nCurRefDlgId )
1861 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1862 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1863 OSL_ENSURE( pChildWnd || pModalDlg, "NoChildWin" );
1864 if ( pChildWnd )
1866 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1867 pRefDlg->AddRefEntry();
1869 else if(pModalDlg)
1870 pModalDlg->AddRefEntry();
1872 else
1874 ScInputHandler* pHdl = GetInputHdl();
1875 if (pHdl)
1876 pHdl->AddRefEntry();
1880 void ScModule::EndReference()
1882 //! move reference dialog handling to view
1883 //! (only keep function autopilot here for references to other documents)
1885 // in Ref-Dialogen wird hiermit auch das Zoom-In wieder aufgehoben
1887 //! ShowRefFrame am InputHdl, wenn der Funktions-AP offen ist ???
1889 if ( nCurRefDlgId )
1891 SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1892 ScAnyRefModalDlg* pModalDlg = GetCurrentAnyRefDlg();
1893 OSL_ENSURE( pChildWnd || pModalDlg, "NoChildWin" );
1894 if ( pChildWnd )
1896 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1897 pRefDlg->SetActive();
1899 else
1900 pModalDlg->SetActive();
1904 //------------------------------------------------------------------
1906 // Idle / Online-Spelling
1908 //------------------------------------------------------------------
1910 void ScModule::AnythingChanged()
1912 sal_uLong nOldTime = aIdleTimer.GetTimeout();
1913 if ( nOldTime != SC_IDLE_MIN )
1914 aIdleTimer.SetTimeout( SC_IDLE_MIN );
1916 nIdleCount = 0;
1919 static void lcl_CheckNeedsRepaint( ScDocShell* pDocShell )
1921 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
1922 while ( pFrame )
1924 SfxViewShell* p = pFrame->GetViewShell();
1925 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
1926 if ( pViewSh )
1927 pViewSh->CheckNeedsRepaint();
1928 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
1932 IMPL_LINK_NOARG(ScModule, IdleHandler)
1934 if ( Application::AnyInput( VCL_INPUT_MOUSEANDKEYBOARD ) )
1936 aIdleTimer.Start(); // Timeout unveraendert
1937 return 0;
1940 bool bMore = false;
1941 bool bAutoSpell = false;
1942 ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(SfxObjectShell::Current());
1944 if ( pDocSh )
1946 ScDocument* pDoc = pDocSh->GetDocument();
1947 bAutoSpell = pDoc->GetDocOptions().IsAutoSpell();
1948 if (pDocSh->IsReadOnly())
1949 bAutoSpell = false;
1951 sal_Bool bLinks = pDoc->IdleCheckLinks();
1952 sal_Bool bWidth = pDoc->IdleCalcTextWidth();
1954 bMore = bLinks || bWidth; // ueberhaupt noch was?
1956 // While calculating a Basic formula, a paint event may have occurred,
1957 // so check the bNeedsRepaint flags for this document's views
1958 if (bWidth)
1959 lcl_CheckNeedsRepaint( pDocSh );
1962 if (bAutoSpell)
1964 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
1965 if (pViewSh)
1967 bool bSpell = pViewSh->ContinueOnlineSpelling();
1968 if (bSpell)
1970 aSpellTimer.Start();
1971 bMore = true;
1976 sal_uLong nOldTime = aIdleTimer.GetTimeout();
1977 sal_uLong nNewTime = nOldTime;
1978 if ( bMore )
1980 nNewTime = SC_IDLE_MIN;
1981 nIdleCount = 0;
1983 else
1985 // SC_IDLE_COUNT mal mit initialem Timeout, dann hochzaehlen
1987 if ( nIdleCount < SC_IDLE_COUNT )
1988 ++nIdleCount;
1989 else
1991 nNewTime += SC_IDLE_STEP;
1992 if ( nNewTime > SC_IDLE_MAX )
1993 nNewTime = SC_IDLE_MAX;
1996 if ( nNewTime != nOldTime )
1997 aIdleTimer.SetTimeout( nNewTime );
1999 aIdleTimer.Start();
2000 return 0;
2003 IMPL_LINK_NOARG(ScModule, SpellTimerHdl)
2005 if ( Application::AnyInput( VCL_INPUT_KEYBOARD ) )
2007 aSpellTimer.Start();
2008 return 0; // dann spaeter wieder...
2011 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
2012 if (pViewSh)
2014 if (pViewSh->ContinueOnlineSpelling())
2015 aSpellTimer.Start();
2017 return 0;
2020 //virtuelle Methoden fuer den Optionendialog
2021 SfxItemSet* ScModule::CreateItemSet( sal_uInt16 nId )
2023 SfxItemSet* pRet = 0;
2024 if(SID_SC_EDITOPTIONS == nId)
2026 pRet = new SfxItemSet( GetPool(),
2027 // TP_CALC:
2028 SID_SCDOCOPTIONS, SID_SCDOCOPTIONS,
2029 // TP_VIEW:
2030 SID_SCVIEWOPTIONS, SID_SCVIEWOPTIONS,
2031 SID_SC_OPT_SYNCZOOM, SID_SC_OPT_SYNCZOOM,
2032 // TP_INPUT:
2033 SID_SC_INPUT_SELECTION,SID_SC_INPUT_MARK_HEADER,
2034 SID_SC_INPUT_TEXTWYSIWYG,SID_SC_INPUT_TEXTWYSIWYG,
2035 SID_SC_INPUT_REPLCELLSWARN,SID_SC_INPUT_REPLCELLSWARN,
2036 SID_SC_INPUT_LEGACY_CELL_SELECTION,SID_SC_INPUT_LEGACY_CELL_SELECTION,
2037 // TP_USERLISTS:
2038 SCITEM_USERLIST, SCITEM_USERLIST,
2039 // TP_PRINT:
2040 SID_SCPRINTOPTIONS, SID_SCPRINTOPTIONS,
2041 // TP_GRID:
2042 SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
2044 SID_ATTR_METRIC, SID_ATTR_METRIC,
2045 SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
2046 // TP_COMPATIBILITY
2047 SID_SC_OPT_KEY_BINDING_COMPAT, SID_SC_OPT_KEY_BINDING_COMPAT,
2048 // TP_DEFAULTS
2049 SID_SCDEFAULTSOPTIONS, SID_SCDEFAULTSOPTIONS,
2050 // TP_FORMULA
2051 SID_SCFORMULAOPTIONS, SID_SCFORMULAOPTIONS,
2052 0 );
2054 const ScAppOptions& rAppOpt = GetAppOptions();
2056 ScDocShell* pDocSh = PTR_CAST(ScDocShell,
2057 SfxObjectShell::Current());
2058 ScDocOptions aCalcOpt = pDocSh
2059 ? pDocSh->GetDocument()->GetDocOptions()
2060 : GetDocOptions();
2062 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,
2063 SfxViewShell::Current());
2064 ScViewOptions aViewOpt = pViewSh
2065 ? pViewSh->GetViewData()->GetOptions()
2066 : GetViewOptions();
2068 ScUserListItem aULItem( SCITEM_USERLIST );
2069 ScUserList* pUL = ScGlobal::GetUserList();
2071 // SFX_APP()->GetOptions( aSet );
2073 pRet->Put( SfxUInt16Item( SID_ATTR_METRIC,
2074 sal::static_int_cast<sal_uInt16>(rAppOpt.GetAppMetric()) ) );
2076 // TP_CALC
2077 pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP,
2078 aCalcOpt.GetTabDistance()));
2079 pRet->Put( ScTpCalcItem( SID_SCDOCOPTIONS, aCalcOpt ) );
2081 // TP_VIEW
2082 pRet->Put( ScTpViewItem( SID_SCVIEWOPTIONS, aViewOpt ) );
2083 pRet->Put( SfxBoolItem( SID_SC_OPT_SYNCZOOM, rAppOpt.GetSynchronizeZoom() ) );
2085 // TP_INPUT
2086 const ScInputOptions& rInpOpt = GetInputOptions();
2087 pRet->Put( SfxUInt16Item( SID_SC_INPUT_SELECTIONPOS,
2088 rInpOpt.GetMoveDir() ) );
2089 pRet->Put( SfxBoolItem( SID_SC_INPUT_SELECTION,
2090 rInpOpt.GetMoveSelection() ) );
2091 pRet->Put( SfxBoolItem( SID_SC_INPUT_EDITMODE,
2092 rInpOpt.GetEnterEdit() ) );
2093 pRet->Put( SfxBoolItem( SID_SC_INPUT_FMT_EXPAND,
2094 rInpOpt.GetExtendFormat() ) );
2095 pRet->Put( SfxBoolItem( SID_SC_INPUT_RANGEFINDER,
2096 rInpOpt.GetRangeFinder() ) );
2097 pRet->Put( SfxBoolItem( SID_SC_INPUT_REF_EXPAND,
2098 rInpOpt.GetExpandRefs() ) );
2099 pRet->Put( SfxBoolItem( SID_SC_INPUT_MARK_HEADER,
2100 rInpOpt.GetMarkHeader() ) );
2101 pRet->Put( SfxBoolItem( SID_SC_INPUT_TEXTWYSIWYG,
2102 rInpOpt.GetTextWysiwyg() ) );
2103 pRet->Put( SfxBoolItem( SID_SC_INPUT_REPLCELLSWARN,
2104 rInpOpt.GetReplaceCellsWarn() ) );
2105 pRet->Put( SfxBoolItem( SID_SC_INPUT_LEGACY_CELL_SELECTION,
2106 rInpOpt.GetLegacyCellSelection() ) );
2109 // RID_SC_TP_PRINT
2110 pRet->Put( ScTpPrintItem( SID_SCPRINTOPTIONS, GetPrintOptions() ) );
2112 // TP_GRID
2113 SvxGridItem* pSvxGridItem = aViewOpt.CreateGridItem();
2114 pRet->Put( *pSvxGridItem );
2115 delete pSvxGridItem;
2117 // TP_USERLISTS
2118 if ( pUL )
2120 aULItem.SetUserList( *pUL );
2121 pRet->Put(aULItem);
2124 // TP_COMPATIBILITY
2125 pRet->Put( SfxUInt16Item( SID_SC_OPT_KEY_BINDING_COMPAT,
2126 rAppOpt.GetKeyBindingType() ) );
2128 // TP_DEFAULTS
2129 pRet->Put( ScTpDefaultsItem( SID_SCDEFAULTSOPTIONS, GetDefaultsOptions() ) );
2131 // TP_FORMULA
2132 pRet->Put( ScTpFormulaItem( SID_SCFORMULAOPTIONS, GetFormulaOptions() ) );
2134 return pRet;
2137 void ScModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
2139 if(SID_SC_EDITOPTIONS == nId)
2141 ModifyOptions( rSet );
2145 SfxTabPage* ScModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
2147 SfxTabPage* pRet = NULL;
2148 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2149 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2150 switch(nId)
2152 case SID_SC_TP_LAYOUT:
2154 ::CreateTabPage ScTpLayoutOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_LAYOUT );
2155 if ( ScTpLayoutOptionsCreate )
2156 pRet = (*ScTpLayoutOptionsCreate) (pParent, rSet);
2158 break;
2159 case SID_SC_TP_CONTENT:
2161 ::CreateTabPage ScTpContentOptionsCreate = pFact->GetTabPageCreatorFunc(RID_SCPAGE_CONTENT);
2162 if ( ScTpContentOptionsCreate )
2163 pRet = (*ScTpContentOptionsCreate)(pParent, rSet);
2165 break;
2166 case SID_SC_TP_GRID: pRet = SvxGridTabPage::Create(pParent, rSet); break;
2167 case SID_SC_TP_USERLISTS:
2169 ::CreateTabPage ScTpUserListsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_USERLISTS );
2170 if ( ScTpUserListsCreate )
2171 pRet = (*ScTpUserListsCreate)( pParent, rSet);
2173 break;
2174 case SID_SC_TP_CALC:
2176 ::CreateTabPage ScTpCalcOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_CALC );
2177 if ( ScTpCalcOptionsCreate )
2178 pRet = (*ScTpCalcOptionsCreate)(pParent, rSet);
2180 break;
2181 case SID_SC_TP_FORMULA:
2183 ::CreateTabPage ScTpFormulaOptionsCreate = pFact->GetTabPageCreatorFunc (RID_SCPAGE_FORMULA);
2184 if (ScTpFormulaOptionsCreate)
2185 pRet = (*ScTpFormulaOptionsCreate)(pParent, rSet);
2187 break;
2188 case SID_SC_TP_COMPATIBILITY:
2190 ::CreateTabPage ScTpCompatOptionsCreate = pFact->GetTabPageCreatorFunc (RID_SCPAGE_COMPATIBILITY);
2191 if (ScTpCompatOptionsCreate)
2192 pRet = (*ScTpCompatOptionsCreate)(pParent, rSet);
2194 break;
2195 case SID_SC_TP_CHANGES:
2197 ::CreateTabPage ScRedlineOptionsTabPageCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_OPREDLINE );
2198 if ( ScRedlineOptionsTabPageCreate )
2199 pRet =(*ScRedlineOptionsTabPageCreate)(pParent, rSet);
2201 break;
2202 case RID_SC_TP_PRINT:
2204 ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
2205 if ( ScTpPrintOptionsCreate )
2206 pRet = (*ScTpPrintOptionsCreate)( pParent, rSet);
2208 break;
2209 case RID_SC_TP_DEFAULTS:
2211 ::CreateTabPage ScTpDefaultsOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_DEFAULTS );
2212 if ( ScTpDefaultsOptionsCreate )
2213 pRet = (*ScTpDefaultsOptionsCreate)( pParent, rSet);
2215 break;
2218 OSL_ENSURE( pRet, "ScModule::CreateTabPage(): no valid ID for TabPage!" );
2220 return pRet;
2223 //------------------------------------------------------------------
2225 IMPL_LINK( ScModule, CalcFieldValueHdl, EditFieldInfo*, pInfo )
2227 //! mit ScFieldEditEngine zusammenfassen !!!
2229 if (pInfo)
2231 const SvxFieldItem& rField = pInfo->GetField();
2232 const SvxFieldData* pField = rField.GetField();
2234 if (pField && pField->ISA(SvxURLField))
2236 /******************************************************************
2237 * URL-Field
2238 ******************************************************************/
2240 const SvxURLField* pURLField = (const SvxURLField*) pField;
2241 OUString aURL = pURLField->GetURL();
2243 switch ( pURLField->GetFormat() )
2245 case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
2246 case SVXURLFORMAT_REPR:
2248 pInfo->SetRepresentation( pURLField->GetRepresentation() );
2250 break;
2252 case SVXURLFORMAT_URL:
2254 pInfo->SetRepresentation( aURL );
2256 break;
2259 svtools::ColorConfigEntry eEntry =
2260 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
2261 pInfo->SetTxtColor( GetColorConfig().GetColorValue(eEntry).nColor );
2263 else
2265 OSL_FAIL("unbekannter Feldbefehl");
2266 pInfo->SetRepresentation(OUString('?'));
2270 return 0;
2273 sal_Bool ScModule::RegisterRefWindow( sal_uInt16 nSlotId, Window *pWnd )
2275 std::list<Window*> & rlRefWindow = m_mapRefWindow[nSlotId];
2277 if( std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd ) == rlRefWindow.end() )
2279 rlRefWindow.push_back( pWnd );
2280 return sal_True;
2283 return false;
2286 sal_Bool ScModule::UnregisterRefWindow( sal_uInt16 nSlotId, Window *pWnd )
2288 std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2290 if( iSlot == m_mapRefWindow.end() )
2291 return false;
2293 std::list<Window*> & rlRefWindow = iSlot->second;
2295 std::list<Window*>::iterator i = std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd );
2297 if( i == rlRefWindow.end() )
2298 return false;
2300 rlRefWindow.erase( i );
2302 if( rlRefWindow.empty() )
2303 m_mapRefWindow.erase( nSlotId );
2305 return sal_True;
2308 sal_Bool ScModule::IsAliveRefDlg( sal_uInt16 nSlotId, Window *pWnd )
2310 std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2312 if( iSlot == m_mapRefWindow.end() )
2313 return false;
2315 std::list<Window*> & rlRefWindow = iSlot->second;
2317 return rlRefWindow.end() != std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd );
2320 Window * ScModule::Find1RefWindow( sal_uInt16 nSlotId, Window *pWndAncestor )
2322 if (!pWndAncestor)
2323 return NULL;
2325 std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2327 if( iSlot == m_mapRefWindow.end() )
2328 return NULL;
2330 std::list<Window*> & rlRefWindow = iSlot->second;
2332 while( Window *pParent = pWndAncestor->GetParent() ) pWndAncestor = pParent;
2334 for( std::list<Window*>::iterator i = rlRefWindow.begin(); i!=rlRefWindow.end(); ++i )
2335 if ( pWndAncestor->IsWindowOrChild( *i, (*i)->IsSystemWindow() ) )
2336 return *i;
2338 return NULL;
2341 ScAnyRefModalDlg* ScModule::GetCurrentAnyRefDlg()
2343 if(!maAnyRefDlgStack.empty())
2344 return maAnyRefDlgStack.top();
2346 return NULL;
2349 void ScModule::PushNewAnyRefDlg( ScAnyRefModalDlg* pNewDlg )
2351 maAnyRefDlgStack.push( pNewDlg );
2353 // prevent mismatch between calls to
2354 // SetInRefMode(true) and SetInRefMode(false)
2355 if(maAnyRefDlgStack.size() != 1)
2356 return;
2358 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
2359 while(pViewShell)
2361 if ( pViewShell->ISA(ScTabViewShell) )
2363 ScTabViewShell* pViewSh = (ScTabViewShell*)pViewShell;
2364 pViewSh->SetInRefMode( true );
2366 pViewShell = SfxViewShell::GetNext( *pViewShell );
2370 void ScModule::PopAnyRefDlg()
2372 maAnyRefDlgStack.pop();
2374 if(maAnyRefDlgStack.empty())
2376 // no modal ref dlg any more
2377 // disable the flag in ScGridWindow
2379 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
2380 while(pViewShell)
2382 if ( pViewShell->ISA(ScTabViewShell) )
2384 ScTabViewShell* pViewSh = (ScTabViewShell*)pViewShell;
2385 pViewSh->SetInRefMode( false );
2387 pViewShell = SfxViewShell::GetNext( *pViewShell );
2393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */