xref: /trunk/main/sc/source/ui/app/scmod.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
31 #include <comphelper/processfactory.hxx>
32 
33 
34 
35 
36 
37 // INCLUDE ---------------------------------------------------------------
38 
39 #include "scitems.hxx"
40 #include <sfx2/app.hxx>
41 #include <editeng/eeitem.hxx>
42 
43 #include <editeng/flditem.hxx>
44 #include <editeng/outliner.hxx>
45 #include <basic/sbstar.hxx>
46 
47 #include <sfx2/sfxdlg.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/objface.hxx>
50 
51 #include <svx/hyprlink.hxx>
52 #include "IAnyRefDialog.hxx"
53 
54 #include <svtools/ehdl.hxx>
55 #include <svtools/accessibilityoptions.hxx>
56 #include <svl/ctloptions.hxx>
57 #include <unotools/useroptions.hxx>
58 #include <vcl/status.hxx>
59 #include <sfx2/bindings.hxx>
60 #include <sfx2/request.hxx>
61 #include <sfx2/printer.hxx>
62 #include <editeng/langitem.hxx>
63 #include <svtools/colorcfg.hxx>
64 
65 #include <svl/whiter.hxx>
66 #include <svx/selctrl.hxx>
67 #include <svx/insctrl.hxx>
68 #include <svx/zoomctrl.hxx>
69 #include <svx/modctrl.hxx>
70 #include <svx/pszctrl.hxx>
71 #include <svx/zoomsliderctrl.hxx>
72 #include <vcl/msgbox.hxx>
73 #include <svl/inethist.hxx>
74 #include <vcl/waitobj.hxx>
75 #include <svx/svxerr.hxx>
76 
77 
78 
79 #include "scmod.hxx"
80 #include "global.hxx"
81 #include "viewopti.hxx"
82 #include "docoptio.hxx"
83 #include "appoptio.hxx"
84 #include "inputopt.hxx"
85 #include "printopt.hxx"
86 #include "navicfg.hxx"
87 #include "addincfg.hxx"
88 #include "tabvwsh.hxx"
89 #include "prevwsh.hxx"
90 #include "docsh.hxx"
91 #include "drwlayer.hxx"
92 #include "uiitems.hxx"
93 #include "sc.hrc"
94 #include "cfgids.hxx"
95 #include "inputhdl.hxx"
96 #include "inputwin.hxx"
97 #include "msgpool.hxx"
98 #include "scresid.hxx"
99 #include "anyrefdg.hxx"
100 #include "dwfunctr.hxx"
101 #include "formdata.hxx"
102 //CHINA001 #include "tpview.hxx"
103 //CHINA001 #include "tpusrlst.hxx"
104 //CHINA001 #include "tpcalc.hxx"
105 #include "tpprint.hxx"
106 //CHINA001 #include "opredlin.hxx"
107 #include "transobj.hxx"
108 #include "detfunc.hxx"
109 #include "preview.hxx"
110 
111 #include <svx/xmlsecctrl.hxx>
112 
113 
114 #define ScModule
115 #include "scslots.hxx"
116 
117 #include "scabstdlg.hxx" //CHINA001
118 
119 #define SC_IDLE_MIN		150
120 #define SC_IDLE_MAX		3000
121 #define SC_IDLE_STEP	75
122 #define SC_IDLE_COUNT	50
123 
124 static sal_uInt16 nIdleCount = 0;
125 
126 //------------------------------------------------------------------
127 
128 SFX_IMPL_INTERFACE( ScModule, SfxShell, ScResId(RID_APPTITLE) )
129 {
130 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER,
131 								ScResId(RID_OBJECTBAR_APP) );
132 	SFX_STATUSBAR_REGISTRATION( ScResId(SCCFG_STATUSBAR) );		// nur ID wichtig
133 	SFX_CHILDWINDOW_REGISTRATION( SvxHyperlinkDlgWrapper::GetChildWindowId() );
134 }
135 
136 //------------------------------------------------------------------
137 
138 ScModule::ScModule( SfxObjectFactory* pFact ) :
139 	SfxModule( SfxApplication::CreateResManager( "sc" ), sal_False, pFact, NULL ),
140 	pSelTransfer( NULL ),
141 	pMessagePool( NULL ),
142 	pRefInputHandler( NULL ),
143 	pViewCfg( NULL ),
144 	pDocCfg( NULL ),
145 	pAppCfg( NULL ),
146 	pInputCfg( NULL ),
147 	pPrintCfg( NULL ),
148 	pNavipiCfg( NULL ),
149     pAddInCfg( NULL ),
150 	pColorConfig( NULL ),
151 	pAccessOptions( NULL ),
152 	pCTLOptions( NULL ),
153     pUserOptions( NULL ),
154 	pErrorHdl( NULL ),
155 	pSvxErrorHdl( NULL ),
156 	pFormEditData( NULL ),
157 	nCurRefDlgId( 0 ),
158 	bIsWaterCan( sal_False ),
159 	bIsInEditCommand( sal_False ),
160     bIsInExecuteDrop( sal_False ),
161     mbIsInSharedDocLoading( false ),
162     mbIsInSharedDocSaving( false )
163 {
164 	//	im ctor ist der ResManager (DLL-Daten) noch nicht initialisiert!
165 
166 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("StarCalc")));		// fuer Basic
167 
168 	ResetDragObject();
169 	SetClipObject( NULL, NULL );
170 
171 	//	InputHandler braucht nicht mehr angelegt zu werden
172 
173 	//	ErrorHandler anlegen - war in Init()
174 	//	zwischen OfficeApplication::Init und ScGlobal::Init
175 	SvxErrorHandler::Get();
176 	pErrorHdl	 = new SfxErrorHandler( RID_ERRHDLSC,
177 										ERRCODE_AREA_SC,
178 										ERRCODE_AREA_APP2-1,
179 										GetResMgr() );
180 
181 	aSpellTimer.SetTimeout(10);
182 	aSpellTimer.SetTimeoutHdl( LINK( this, ScModule, SpellTimerHdl ) );
183 	aIdleTimer.SetTimeout(SC_IDLE_MIN);
184 	aIdleTimer.SetTimeoutHdl( LINK( this, ScModule, IdleHandler ) );
185 	aIdleTimer.Start();
186 
187 	pMessagePool = new ScMessagePool;
188 	pMessagePool->FreezeIdRanges();
189 	SetPool( pMessagePool );
190 	ScGlobal::InitTextHeight( pMessagePool );
191 
192 	StartListening( *SFX_APP() );		// for SFX_HINT_DEINITIALIZING
193 }
194 
195 ScModule::~ScModule()
196 {
197 	DBG_ASSERT( !pSelTransfer, "Selection Transfer object not deleted" );
198 
199 	//	InputHandler braucht nicht mehr geloescht zu werden (gibt keinen an der App mehr)
200 
201 	SfxItemPool::Free(pMessagePool);
202 
203 	DELETEZ( pFormEditData );
204 
205 	delete pErrorHdl;
206 //	delete pSvxErrorHdl;
207 
208 	ScGlobal::Clear();		// ruft auch ScDocumentPool::DeleteVersionMaps();
209 
210 	DeleteCfg();			// wurde mal aus Exit() gerufen
211 }
212 
213 //------------------------------------------------------------------
214 void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 )
215 {
216 	if ( p == pColorConfig || p == pAccessOptions )
217 	{
218 		//	Test if detective objects have to be updated with new colors
219 		//	(if the detective colors haven't been used yet, there's nothing to update)
220 		if ( ScDetectiveFunc::IsColorsInitialized() )
221 		{
222             const svtools::ColorConfig& rColors = GetColorConfig();
223 			sal_Bool bArrows =
224                 ( ScDetectiveFunc::GetArrowColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVE).nColor ||
225                   ScDetectiveFunc::GetErrorColor() != (ColorData)rColors.GetColorValue(svtools::CALCDETECTIVEERROR).nColor );
226 			sal_Bool bComments =
227                 ( ScDetectiveFunc::GetCommentColor() != (ColorData)rColors.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor );
228 			if ( bArrows || bComments )
229 			{
230 				ScDetectiveFunc::InitializeColors();		// get the new colors
231 
232 				//	update detective objects in all open documents
233 				SfxObjectShell*	pObjSh = SfxObjectShell::GetFirst();
234 				while ( pObjSh )
235 				{
236 					if ( pObjSh->Type() == TYPE(ScDocShell) )
237 					{
238 						ScDocShell* pDocSh = ((ScDocShell*)pObjSh);
239 						if ( bArrows )
240                             ScDetectiveFunc( pDocSh->GetDocument(), 0 ).UpdateAllArrowColors();
241 						if ( bComments )
242                             ScDetectiveFunc::UpdateAllComments( *pDocSh->GetDocument() );
243 					}
244 					pObjSh = SfxObjectShell::GetNext( *pObjSh );
245 				}
246 			}
247 		}
248 
249 		//	force all views to repaint, using the new options
250 
251         SfxViewShell* pViewShell = SfxViewShell::GetFirst();
252         while(pViewShell)
253         {
254         	if ( pViewShell->ISA(ScTabViewShell) )
255         	{
256         		ScTabViewShell* pViewSh = (ScTabViewShell*)pViewShell;
257 				pViewSh->PaintGrid();
258 				pViewSh->PaintTop();
259 				pViewSh->PaintLeft();
260 				pViewSh->PaintExtras();
261 
262 				ScInputHandler* pHdl = pViewSh->GetInputHandler();
263 				if ( pHdl )
264 					pHdl->ForgetLastPattern();	// EditEngine BackgroundColor may change
265         	}
266         	else if ( pViewShell->ISA(ScPreviewShell) )
267         	{
268         		Window* pWin = pViewShell->GetWindow();
269         		if (pWin)
270         			pWin->Invalidate();
271         	}
272             pViewShell = SfxViewShell::GetNext( *pViewShell );
273         }
274 	}
275     else if ( p == pCTLOptions )
276     {
277 		//	for all documents: set digit language for printer, recalc output factor, update row heights
278 		SfxObjectShell*	pObjSh = SfxObjectShell::GetFirst();
279 		while ( pObjSh )
280 		{
281 			if ( pObjSh->Type() == TYPE(ScDocShell) )
282 			{
283 				ScDocShell* pDocSh = ((ScDocShell*)pObjSh);
284 				OutputDevice* pPrinter = pDocSh->GetPrinter();
285 				if ( pPrinter )
286 					pPrinter->SetDigitLanguage( GetOptDigitLanguage() );
287 
288 				pDocSh->CalcOutputFactor();
289 
290 				SCTAB nTabCount = pDocSh->GetDocument()->GetTableCount();
291 				for (SCTAB nTab=0; nTab<nTabCount; nTab++)
292 					pDocSh->AdjustRowHeight( 0, MAXROW, nTab );
293 			}
294 			pObjSh = SfxObjectShell::GetNext( *pObjSh );
295 		}
296 
297 		//	for all views (table and preview): update digit language
298 		SfxViewShell* pSh = SfxViewShell::GetFirst();
299 		while ( pSh )
300 		{
301 			if ( pSh->ISA( ScTabViewShell ) )
302 			{
303 				ScTabViewShell* pViewSh = (ScTabViewShell*)pSh;
304 
305 				//	set ref-device for EditEngine (re-evaluates digit settings)
306 				ScInputHandler* pHdl = GetInputHdl(pViewSh);
307 				if (pHdl)
308 					pHdl->UpdateRefDevice();
309 
310 				pViewSh->DigitLanguageChanged();
311 				pViewSh->PaintGrid();
312 			}
313 			else if ( pSh->ISA( ScPreviewShell ) )
314 			{
315 				ScPreviewShell* pPreviewSh = (ScPreviewShell*)pSh;
316 			    ScPreview* pPreview = pPreviewSh->GetPreview();
317 
318 		    	pPreview->SetDigitLanguage( GetOptDigitLanguage() );
319 		    	pPreview->Invalidate();
320 			}
321 
322 			pSh = SfxViewShell::GetNext( *pSh );
323 		}
324     }
325 }
326 
327 void ScModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
328 {
329 	if ( rHint.ISA(SfxSimpleHint) )
330 	{
331         sal_uLong nHintId = ((SfxSimpleHint&)rHint).GetId();
332         if ( nHintId == SFX_HINT_DEINITIALIZING )
333 		{
334 			//	ConfigItems must be removed before ConfigManager
335 			DeleteCfg();
336 		}
337 	}
338 }
339 
340 //------------------------------------------------------------------
341 
342 void ScModule::DeleteCfg()
343 {
344 	DELETEZ( pViewCfg ); // Speichern passiert vor Exit() automatisch
345 	DELETEZ( pDocCfg );
346 	DELETEZ( pAppCfg );
347 	DELETEZ( pInputCfg );
348 	DELETEZ( pPrintCfg );
349 	DELETEZ( pNavipiCfg );
350     DELETEZ( pAddInCfg );
351 
352 	if ( pColorConfig )
353 	{
354 		pColorConfig->RemoveListener(this);
355 		DELETEZ( pColorConfig );
356 	}
357 	if ( pAccessOptions )
358 	{
359 	    pAccessOptions->RemoveListener(this);
360 		DELETEZ( pAccessOptions );
361 	}
362 	if ( pCTLOptions )
363 	{
364 	    pCTLOptions->RemoveListener(this);
365 		DELETEZ( pCTLOptions );
366 	}
367     if( pUserOptions )
368     {
369         DELETEZ( pUserOptions );
370     }
371 }
372 
373 //------------------------------------------------------------------
374 //
375 //		von der Applikation verschoben:
376 //
377 //------------------------------------------------------------------
378 
379 void ScModule::Execute( SfxRequest& rReq )
380 {
381 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
382 	SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : NULL;
383 
384 	const SfxItemSet*	pReqArgs	= rReq.GetArgs();
385 	sal_uInt16				nSlot		= rReq.GetSlot();
386 
387 	switch ( nSlot )
388 	{
389 		case SID_CHOOSE_DESIGN:
390 			{
391 				String aMacroName =
392 					String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Template.Samples.ShowStyles"));
393                 SfxApplication::CallAppBasic( aMacroName );
394 			}
395 			break;
396 		case SID_EURO_CONVERTER:
397 			{
398 				String aMacroName =
399 					String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Euro.ConvertRun.Main"));
400 				SfxApplication::CallAppBasic( aMacroName );
401 			}
402 			break;
403 		case SID_AUTOSPELL_CHECK:
404 			{
405 				sal_Bool bSet;
406 				const SfxPoolItem* pItem;
407 				if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
408 					bSet = ((const SfxBoolItem*)pItem)->GetValue();
409 				else
410 				{						//	Toggle
411 					ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
412 					if ( pDocSh )
413 						bSet = !pDocSh->GetDocument()->GetDocOptions().IsAutoSpell();
414 					else
415 						bSet = !GetDocOptions().IsAutoSpell();
416 				}
417 
418 				SfxItemSet aSet( GetPool(), SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK );
419 				aSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, bSet ) );
420 				ModifyOptions( aSet );
421 				rReq.Done();
422 			}
423 			break;
424 
425 		case SID_ATTR_METRIC:
426 			{
427 				const SfxPoolItem* pItem;
428 				if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
429 				{
430 					FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue();
431 					switch( eUnit )
432 					{
433 						case FUNIT_MM:		// nur die Einheiten, die auch im Dialog stehen
434 						case FUNIT_CM:
435 						case FUNIT_INCH:
436 						case FUNIT_PICA:
437 						case FUNIT_POINT:
438 							{
439 								PutItem( *pItem );
440 								ScAppOptions aNewOpts( GetAppOptions() );
441 								aNewOpts.SetAppMetric( eUnit );
442 								SetAppOptions( aNewOpts );
443 								rReq.Done();
444 							}
445 							break;
446                         default:
447                         {
448                             // added to avoid warnings
449                         }
450 					}
451 				}
452 			}
453 			break;
454 
455 		case FID_AUTOCOMPLETE:
456 			{
457 				ScAppOptions aNewOpts( GetAppOptions() );
458 				sal_Bool bNew = !aNewOpts.GetAutoComplete();
459 				aNewOpts.SetAutoComplete( bNew );
460 				SetAppOptions( aNewOpts );
461 				ScInputHandler::SetAutoComplete( bNew );
462 				if (pBindings)
463 					pBindings->Invalidate( FID_AUTOCOMPLETE );
464 				rReq.Done();
465 			}
466 			break;
467 
468 		case SID_DETECTIVE_AUTO:
469 			{
470 				ScAppOptions aNewOpts( GetAppOptions() );
471 				sal_Bool bNew = !aNewOpts.GetDetectiveAuto();
472                 SFX_REQUEST_ARG( rReq, pAuto, SfxBoolItem, SID_DETECTIVE_AUTO, sal_False );
473                 if ( pAuto )
474                     bNew = pAuto->GetValue();
475 
476 				aNewOpts.SetDetectiveAuto( bNew );
477 				SetAppOptions( aNewOpts );
478 				if (pBindings)
479 					pBindings->Invalidate( SID_DETECTIVE_AUTO );
480                 rReq.AppendItem( SfxBoolItem( SID_DETECTIVE_AUTO, bNew ) );
481 				rReq.Done();
482 			}
483 			break;
484 
485 		case SID_PSZ_FUNCTION:
486 			if (pReqArgs)
487 			{
488 				const SfxUInt16Item& rItem = (const SfxUInt16Item&)pReqArgs->Get(SID_PSZ_FUNCTION);
489 				DBG_ASSERT(rItem.ISA(SfxUInt16Item),"falscher Parameter");
490 
491 				ScAppOptions aNewOpts( GetAppOptions() );
492 				aNewOpts.SetStatusFunc( rItem.GetValue() );
493 				SetAppOptions( aNewOpts );
494 
495 				if (pBindings)
496 				{
497 					pBindings->Invalidate( SID_TABLE_CELL );
498 					pBindings->Update( SID_TABLE_CELL );			// sofort
499 
500 					pBindings->Invalidate( SID_PSZ_FUNCTION );
501 					pBindings->Update( SID_PSZ_FUNCTION );
502 					// falls Menue gleich wieder aufgeklappt wird
503 				}
504 			}
505 			break;
506 
507 		case SID_ATTR_LANGUAGE:
508 		case SID_ATTR_CHAR_CJK_LANGUAGE:
509 		case SID_ATTR_CHAR_CTL_LANGUAGE:
510 			{
511 				const SfxPoolItem* pItem;
512 				if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( GetPool().GetWhich(nSlot), sal_True, &pItem ) )
513 				{
514 					ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
515 					ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : NULL;
516 					if ( pDoc )
517 					{
518 						LanguageType eNewLang = ((SvxLanguageItem*)pItem)->GetLanguage();
519 						LanguageType eLatin, eCjk, eCtl;
520 						pDoc->GetLanguage( eLatin, eCjk, eCtl );
521 						LanguageType eOld = ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE ) ? eCjk :
522 											( ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE ) ? eCtl : eLatin );
523 						if ( eNewLang != eOld )
524 						{
525 							if ( nSlot == SID_ATTR_CHAR_CJK_LANGUAGE )
526 								eCjk = eNewLang;
527 							else if ( nSlot == SID_ATTR_CHAR_CTL_LANGUAGE )
528 								eCtl = eNewLang;
529 							else
530 								eLatin = eNewLang;
531 
532 							pDoc->SetLanguage( eLatin, eCjk, eCtl );
533 
534 							ScInputHandler* pInputHandler = GetInputHdl();
535 							if ( pInputHandler )
536 								pInputHandler->UpdateSpellSettings();	// EditEngine-Flags
537 							ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
538 							if ( pViewSh )
539 								pViewSh->UpdateDrawTextOutliner();		// EditEngine-Flags
540 
541                             pDocSh->SetDocumentModified();
542 						}
543 					}
544 				}
545 			}
546 			break;
547 
548 		case FID_FOCUS_POSWND:
549 			{
550 				ScInputHandler* pHdl = GetInputHdl();
551 				if (pHdl)
552 				{
553 					ScInputWindow* pWin = pHdl->GetInputWindow();
554 					if (pWin)
555 						pWin->PosGrabFocus();
556 				}
557 				rReq.Done();
558 			}
559 			break;
560 
561         case SID_OPEN_XML_FILTERSETTINGS:
562         {
563 			try
564 			{
565 				com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XExecutableDialog > xDialog(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.comp.ui.XSLTFilterDialog")), com::sun::star::uno::UNO_QUERY);
566 				if( xDialog.is() )
567 				{
568 					xDialog->execute();
569 				}
570 			}
571 			catch( ::com::sun::star::uno::RuntimeException& )
572 			{
573 			}
574 		}
575 		break;
576 
577 		default:
578 			DBG_ERROR( "ScApplication: Unknown Message." );
579 			break;
580 	}
581 }
582 
583 void ScModule::GetState( SfxItemSet& rSet )
584 {
585 	SfxWhichIter aIter(rSet);
586 	sal_uInt16 nWhich = aIter.FirstWhich();
587 	while ( nWhich )
588 	{
589 		switch ( nWhich )
590 		{
591 			case FID_AUTOCOMPLETE:
592 				rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetAutoComplete() ) );
593 				break;
594 			case SID_DETECTIVE_AUTO:
595 				rSet.Put( SfxBoolItem( nWhich, GetAppOptions().GetDetectiveAuto() ) );
596 				break;
597 			case SID_PSZ_FUNCTION:
598 				rSet.Put( SfxUInt16Item( nWhich, GetAppOptions().GetStatusFunc() ) );
599 				break;
600 			case SID_ATTR_METRIC:
601                 rSet.Put( SfxUInt16Item( nWhich, sal::static_int_cast<sal_uInt16>(GetAppOptions().GetAppMetric()) ) );
602 				break;
603 			case SID_AUTOSPELL_CHECK:
604 				{
605 					sal_Bool bAuto;
606 					ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
607 					if ( pDocSh )
608 						bAuto = pDocSh->GetDocument()->GetDocOptions().IsAutoSpell();
609 					else
610 					{
611 						sal_uInt16 nDummyLang, nDummyCjk, nDummyCtl;
612                         GetSpellSettings( nDummyLang, nDummyCjk, nDummyCtl, bAuto );
613 					}
614 					rSet.Put( SfxBoolItem( nWhich, bAuto ) );
615 				}
616 				break;
617 			case SID_ATTR_LANGUAGE:
618 			case ATTR_CJK_FONT_LANGUAGE:		// WID for SID_ATTR_CHAR_CJK_LANGUAGE
619 			case ATTR_CTL_FONT_LANGUAGE:		// WID for SID_ATTR_CHAR_CTL_LANGUAGE
620 				{
621 					ScDocShell* pDocSh = PTR_CAST(ScDocShell, SfxObjectShell::Current());
622 					ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : NULL;
623 					if ( pDoc )
624 					{
625 						LanguageType eLatin, eCjk, eCtl;
626 						pDoc->GetLanguage( eLatin, eCjk, eCtl );
627 						LanguageType eLang = ( nWhich == ATTR_CJK_FONT_LANGUAGE ) ? eCjk :
628 											( ( nWhich == ATTR_CTL_FONT_LANGUAGE ) ? eCtl : eLatin );
629 						rSet.Put( SvxLanguageItem( eLang, nWhich ) );
630 					}
631 				}
632 				break;
633 
634 		}
635 		nWhich = aIter.NextWhich();
636 	}
637 }
638 
639 
640 void ScModule::HideDisabledSlots( SfxItemSet& rSet )
641 {
642     if( SfxViewFrame* pViewFrm = SfxViewFrame::Current() )
643     {
644         SfxBindings& rBindings = pViewFrm->GetBindings();
645         SfxWhichIter aIter( rSet );
646         for( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich != 0; nWhich = aIter.NextWhich() )
647         {
648             ScViewUtil::HideDisabledSlot( rSet, rBindings, nWhich );
649             // always disable the slots
650             rSet.DisableItem( nWhich );
651         }
652     }
653 }
654 
655 
656 //------------------------------------------------------------------
657 
658 void ScModule::ResetDragObject()
659 {
660 	aDragData.pCellTransfer = NULL;
661 	aDragData.pDrawTransfer = NULL;
662 
663 	aDragData.aLinkDoc.Erase();
664 	aDragData.aLinkTable.Erase();
665 	aDragData.aLinkArea.Erase();
666 	aDragData.pJumpLocalDoc = NULL;
667 	aDragData.aJumpTarget.Erase();
668 	aDragData.aJumpText.Erase();
669 }
670 
671 void ScModule::SetDragObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
672 {
673 	ResetDragObject();
674 	aDragData.pCellTransfer = pCellObj;
675 	aDragData.pDrawTransfer = pDrawObj;
676 }
677 
678 void ScModule::SetDragLink( const String& rDoc, const String& rTab, const String& rArea )
679 {
680 	ResetDragObject();
681 
682 	aDragData.aLinkDoc	 = rDoc;
683 	aDragData.aLinkTable = rTab;
684 	aDragData.aLinkArea	 = rArea;
685 }
686 
687 void ScModule::SetDragJump( ScDocument* pLocalDoc, const String& rTarget, const String& rText )
688 {
689 	ResetDragObject();
690 
691 	aDragData.pJumpLocalDoc = pLocalDoc;
692 	aDragData.aJumpTarget = rTarget;
693 	aDragData.aJumpText = rText;
694 }
695 
696 //------------------------------------------------------------------
697 
698 void ScModule::SetClipObject( ScTransferObj* pCellObj, ScDrawTransferObj* pDrawObj )
699 {
700 	DBG_ASSERT( !pCellObj || !pDrawObj, "SetClipObject: not allowed to set both objects" );
701 
702 	aClipData.pCellClipboard = pCellObj;
703 	aClipData.pDrawClipboard = pDrawObj;
704 }
705 
706 ScDocument* ScModule::GetClipDoc()
707 {
708 	//	called from document
709 
710 	ScTransferObj* pObj = ScTransferObj::GetOwnClipboard( NULL );
711 	if (pObj)
712 		return pObj->GetDocument();
713 
714 	return NULL;
715 }
716 
717 //------------------------------------------------------------------
718 
719 void ScModule::SetSelectionTransfer( ScSelectionTransferObj* pNew )
720 {
721 	pSelTransfer = pNew;
722 }
723 
724 //------------------------------------------------------------------
725 
726 void ScModule::InitFormEditData()
727 {
728 	pFormEditData = new ScFormEditData;
729 }
730 
731 void ScModule::ClearFormEditData()
732 {
733 	DELETEZ( pFormEditData );
734 }
735 
736 //------------------------------------------------------------------
737 
738 void ScModule::SetViewOptions( const ScViewOptions& rOpt )
739 {
740 	if ( !pViewCfg )
741 		pViewCfg = new ScViewCfg;
742 
743 	pViewCfg->SetOptions( rOpt );
744 }
745 
746 const ScViewOptions& ScModule::GetViewOptions()
747 {
748 	if ( !pViewCfg )
749 		pViewCfg = new ScViewCfg;
750 
751 	return *pViewCfg;
752 }
753 
754 void ScModule::SetDocOptions( const ScDocOptions& rOpt )
755 {
756 	if ( !pDocCfg )
757 		pDocCfg = new ScDocCfg;
758 
759 	pDocCfg->SetOptions( rOpt );
760 }
761 
762 const ScDocOptions& ScModule::GetDocOptions()
763 {
764 	if ( !pDocCfg )
765 		pDocCfg = new ScDocCfg;
766 
767 	return *pDocCfg;
768 }
769 
770 #ifndef	LRU_MAX
771 #define LRU_MAX 10
772 #endif
773 
774 void ScModule::InsertEntryToLRUList(sal_uInt16 nFIndex)
775 {
776 	if(nFIndex != 0)
777 	{
778 		const ScAppOptions& rAppOpt = GetAppOptions();
779 		sal_uInt16 nLRUFuncCount = Min( rAppOpt.GetLRUFuncListCount(), (sal_uInt16)LRU_MAX );
780 		sal_uInt16*	pLRUListIds = rAppOpt.GetLRUFuncList();
781 
782 		sal_uInt16	aIdxList[LRU_MAX];
783 		sal_uInt16	n = 0;
784 		sal_Bool	bFound = sal_False;
785 
786 		while ((n < LRU_MAX) && n<nLRUFuncCount)						// alte Liste abklappern
787 		{
788 			if (!bFound && (pLRUListIds[n]== nFIndex))
789 				bFound = sal_True;											// erster! Treffer
790 			else if (bFound)
791 				aIdxList[n  ] = pLRUListIds[n];							// hinter Treffer kopieren
792 			else if ((n+1) < LRU_MAX)
793 				aIdxList[n+1] = pLRUListIds[n];							// vor Treffer verschieben
794 			n++;
795 		}
796 		if (!bFound && (n < LRU_MAX))									// Eintrag nicht gefunden?
797 			n++;														//  einen mehr
798 		aIdxList[0] = nFIndex;											// Current on Top
799 
800 		ScAppOptions aNewOpts(rAppOpt);									// an App melden
801 		aNewOpts.SetLRUFuncList(aIdxList, n);
802 		SetAppOptions(aNewOpts);
803 
804 		RecentFunctionsChanged();
805 	}
806 }
807 
808 void ScModule::RecentFunctionsChanged()
809 {
810 	//	update function list window
811 	sal_uInt16 nFuncListID = ScFunctionChildWindow::GetChildWindowId();
812 
813 	//!	notify all views
814 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
815 	if ( pViewFrm && pViewFrm->HasChildWindow(nFuncListID) )
816 	{
817 		ScFunctionChildWindow* pWnd =(ScFunctionChildWindow*)pViewFrm->GetChildWindow( nFuncListID );
818 
819 		ScFunctionDockWin* pFuncList=(ScFunctionDockWin*)pWnd->GetWindow();
820 
821 		pFuncList->InitLRUList();
822 	}
823 }
824 
825 void ScModule::SetAppOptions( const ScAppOptions& rOpt )
826 {
827 	if ( !pAppCfg )
828 		pAppCfg = new ScAppCfg;
829 
830 	pAppCfg->SetOptions( rOpt );
831 }
832 
833 void global_InitAppOptions()
834 {
835 	SC_MOD()->GetAppOptions();
836 }
837 
838 const ScAppOptions& ScModule::GetAppOptions()
839 {
840 	if ( !pAppCfg )
841 		pAppCfg = new ScAppCfg;
842 
843 	return *pAppCfg;
844 }
845 
846 void ScModule::SetInputOptions( const ScInputOptions& rOpt )
847 {
848 	if ( !pInputCfg )
849 		pInputCfg = new ScInputCfg;
850 
851 	pInputCfg->SetOptions( rOpt );
852 }
853 
854 const ScInputOptions& ScModule::GetInputOptions()
855 {
856 	if ( !pInputCfg )
857 		pInputCfg = new ScInputCfg;
858 
859 	return *pInputCfg;
860 }
861 
862 void ScModule::SetPrintOptions( const ScPrintOptions& rOpt )
863 {
864 	if ( !pPrintCfg )
865 		pPrintCfg = new ScPrintCfg;
866 
867 	pPrintCfg->SetOptions( rOpt );
868 }
869 
870 const ScPrintOptions& ScModule::GetPrintOptions()
871 {
872 	if ( !pPrintCfg )
873 		pPrintCfg = new ScPrintCfg;
874 
875 	return *pPrintCfg;
876 }
877 
878 ScNavipiCfg& ScModule::GetNavipiCfg()
879 {
880 	if ( !pNavipiCfg )
881 		pNavipiCfg = new ScNavipiCfg;
882 
883 	return *pNavipiCfg;
884 }
885 
886 ScAddInCfg& ScModule::GetAddInCfg()
887 {
888 	if ( !pAddInCfg )
889 		pAddInCfg = new ScAddInCfg;
890 
891 	return *pAddInCfg;
892 }
893 
894 svtools::ColorConfig& ScModule::GetColorConfig()
895 {
896 	if ( !pColorConfig )
897 	{
898         pColorConfig = new svtools::ColorConfig;
899 	    pColorConfig->AddListener(this);
900 	}
901 
902 	return *pColorConfig;
903 }
904 
905 SvtAccessibilityOptions& ScModule::GetAccessOptions()
906 {
907 	if ( !pAccessOptions )
908 	{
909 		pAccessOptions = new SvtAccessibilityOptions;
910 		pAccessOptions->AddListener(this);
911 	}
912 
913 	return *pAccessOptions;
914 }
915 
916 SvtCTLOptions& ScModule::GetCTLOptions()
917 {
918 	if ( !pCTLOptions )
919 	{
920 		pCTLOptions = new SvtCTLOptions;
921 		pCTLOptions->AddListener(this);
922 	}
923 
924 	return *pCTLOptions;
925 }
926 
927 SvtUserOptions&  ScModule::GetUserOptions()
928 {
929     if( !pUserOptions )
930     {
931         pUserOptions = new SvtUserOptions;
932     }
933     return *pUserOptions;
934 }
935 
936 sal_uInt16 ScModule::GetOptDigitLanguage()
937 {
938 	SvtCTLOptions::TextNumerals eNumerals = GetCTLOptions().GetCTLTextNumerals();
939 	return ( eNumerals == SvtCTLOptions::NUMERALS_ARABIC ) ? LANGUAGE_ENGLISH_US :
940 		   ( eNumerals == SvtCTLOptions::NUMERALS_HINDI)   ? LANGUAGE_ARABIC_SAUDI_ARABIA :
941 															 LANGUAGE_SYSTEM;
942 }
943 
944 //------------------------------------------------------------------
945 //
946 //							Optionen
947 //
948 //------------------------------------------------------------------
949 
950 //
951 //		ModifyOptions - Items aus Calc-Options-Dialog
952 //                      und SID_AUTOSPELL_CHECK
953 //
954 
955 #define IS_AVAILABLE(w,item) (SFX_ITEM_SET==rOptSet.GetItemState((w),sal_True,&item))
956 
957 void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
958 {
959 	sal_uInt16 nOldSpellLang, nOldCjkLang, nOldCtlLang;
960     sal_Bool bOldAutoSpell;
961     GetSpellSettings( nOldSpellLang, nOldCjkLang, nOldCtlLang, bOldAutoSpell );
962 
963 	if (!pAppCfg)
964 		GetAppOptions();
965 	DBG_ASSERT( pAppCfg, "AppOptions not initialised :-(" );
966 
967 	if (!pInputCfg)
968 		GetInputOptions();
969 	DBG_ASSERT( pInputCfg, "InputOptions not initialised :-(" );
970 
971 	//--------------------------------------------------------------
972 
973 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
974 	SfxBindings* pBindings = pViewFrm ? &pViewFrm->GetBindings() : NULL;
975 
976 	ScTabViewShell*			pViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
977 	ScDocShell*				pDocSh  = PTR_CAST(ScDocShell, SfxObjectShell::Current());
978 	ScDocument*				pDoc    = pDocSh ? pDocSh->GetDocument() : NULL;
979 	const SfxPoolItem*		pItem	= NULL;
980 	sal_Bool					bRepaint			= sal_False;
981 	sal_Bool					bUpdateMarks		= sal_False;
982 	sal_Bool					bUpdateRefDev		= sal_False;
983 	sal_Bool					bCalcAll			= sal_False;
984 	sal_Bool					bSaveSpellCheck		= sal_False;
985 	sal_Bool					bSaveAppOptions		= sal_False;
986 	sal_Bool					bSaveInputOptions	= sal_False;
987 
988 	//--------------------------------------------------------------------------
989 
990     //  SFX_APP()->SetOptions( rOptSet );
991 
992 	//	Linguistik nicht mehr
993 
994 	if ( IS_AVAILABLE(SID_ATTR_METRIC,pItem) )
995 	{
996 		PutItem( *pItem );
997 		pAppCfg->SetAppMetric( (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue() );
998 		bSaveAppOptions = sal_True;
999 	}
1000 
1001 	if ( IS_AVAILABLE(SCITEM_USERLIST,pItem) )
1002 	{
1003 		ScGlobal::SetUserList( ((const ScUserListItem*)pItem)->GetUserList() );
1004 		bSaveAppOptions = sal_True;
1005 	}
1006 
1007     if ( IS_AVAILABLE(SID_SC_OPT_SYNCZOOM,pItem) )
1008     {
1009         pAppCfg->SetSynchronizeZoom( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
1010         bSaveAppOptions = sal_True;
1011     }
1012 
1013 	//============================================
1014 	// ViewOptions
1015 	//============================================
1016 
1017 	if ( IS_AVAILABLE(SID_SCVIEWOPTIONS,pItem) )
1018 	{
1019 		const ScViewOptions& rNewOpt = ((const ScTpViewItem*)pItem)->GetViewOptions();
1020 
1021 		if ( pViewSh )
1022 		{
1023 			ScViewData*				pViewData = pViewSh->GetViewData();
1024 			const ScViewOptions&	rOldOpt	  = pViewData->GetOptions();
1025 
1026 			sal_Bool bAnchorList = ( rOldOpt.GetOption( VOPT_ANCHOR ) !=
1027 								 rNewOpt.GetOption( VOPT_ANCHOR ) );
1028 
1029 			if ( rOldOpt != rNewOpt )
1030 			{
1031 				pViewData->SetOptions( rNewOpt );	// veraendert rOldOpt
1032 				pViewData->GetDocument()->SetViewOptions( rNewOpt );
1033 				pDocSh->SetDocumentModified();
1034 				bRepaint = sal_True;
1035 			}
1036 			if ( bAnchorList )
1037 				pViewSh->UpdateAnchorHandles();
1038 		}
1039 		SetViewOptions( rNewOpt );
1040 		if (pBindings)
1041 			pBindings->Invalidate(SID_HELPLINES_MOVE);
1042 	}
1043 
1044 	//============================================
1045 	// GridOptions, Auswertung nach ViewOptions,
1046 	// da GridOptions Member der ViewOptions ist!
1047 	//============================================
1048 
1049 	if ( IS_AVAILABLE(SID_ATTR_GRID_OPTIONS,pItem) )
1050 	{
1051 		ScGridOptions aNewGridOpt( (const SvxOptionsGrid&)((const SvxGridItem&)*pItem) );
1052 
1053 		if ( pViewSh )
1054 		{
1055 			ScViewData*			 pViewData = pViewSh->GetViewData();
1056 			ScViewOptions		 aNewViewOpt( pViewData->GetOptions() );
1057 			const ScGridOptions& rOldGridOpt = aNewViewOpt.GetGridOptions();
1058 
1059 			if ( rOldGridOpt != aNewGridOpt )
1060 			{
1061 				aNewViewOpt.SetGridOptions( aNewGridOpt );
1062 				pViewData->SetOptions( aNewViewOpt );
1063 				pViewData->GetDocument()->SetViewOptions( aNewViewOpt );
1064 				pDocSh->SetDocumentModified();
1065 				bRepaint = sal_True;
1066 			}
1067 		}
1068 		ScViewOptions aNewViewOpt ( GetViewOptions() );
1069 		aNewViewOpt.SetGridOptions( aNewGridOpt );
1070 		SetViewOptions( aNewViewOpt );
1071 		if (pBindings)
1072 		{
1073 			pBindings->Invalidate(SID_GRID_VISIBLE);
1074 			pBindings->Invalidate(SID_GRID_USE);
1075 		}
1076 	}
1077 
1078 
1079 	//============================================
1080 	// DocOptions
1081 	//============================================
1082 
1083 	if ( IS_AVAILABLE(SID_SCDOCOPTIONS,pItem) )
1084 	{
1085 		const ScDocOptions&	rNewOpt	= ((const ScTpCalcItem*)pItem)->GetDocOptions();
1086 
1087 		if ( pDoc )
1088 		{
1089 			const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1090 
1091 			bRepaint = ( bRepaint || ( rOldOpt != rNewOpt )   );
1092 			bCalcAll =   bRepaint &&
1093 						 (  rOldOpt.IsIter()       != rNewOpt.IsIter()
1094 						 || rOldOpt.GetIterCount() != rNewOpt.GetIterCount()
1095 						 || rOldOpt.GetIterEps()   != rNewOpt.GetIterEps()
1096 						 || rOldOpt.IsIgnoreCase() != rNewOpt.IsIgnoreCase()
1097 						 || rOldOpt.IsCalcAsShown() != rNewOpt.IsCalcAsShown()
1098 						 || (rNewOpt.IsCalcAsShown() &&
1099 							rOldOpt.GetStdPrecision() != rNewOpt.GetStdPrecision())
1100 						 || rOldOpt.IsMatchWholeCell() != rNewOpt.IsMatchWholeCell()
1101 						 || rOldOpt.GetYear2000()	!= rNewOpt.GetYear2000()
1102                          || rOldOpt.IsFormulaRegexEnabled() != rNewOpt.IsFormulaRegexEnabled()
1103 						 );
1104 			pDoc->SetDocOptions( rNewOpt );
1105 			pDocSh->SetDocumentModified();
1106 		}
1107 		SetDocOptions( rNewOpt );
1108 	}
1109 
1110 	// nach den eigentlichen DocOptions auch noch die TabDistance setzen
1111 	if ( IS_AVAILABLE(SID_ATTR_DEFTABSTOP,pItem) )
1112 	{
1113 		sal_uInt16 nTabDist = ((SfxUInt16Item*)pItem)->GetValue();
1114 		ScDocOptions aOpt(GetDocOptions());
1115 		aOpt.SetTabDistance(nTabDist);
1116 		SetDocOptions( aOpt );
1117 
1118 		if ( pDoc )
1119 		{
1120             ScDocOptions aDocOpt(pDoc->GetDocOptions());
1121             aDocOpt.SetTabDistance(nTabDist);
1122             pDoc->SetDocOptions( aDocOpt );
1123 			pDocSh->SetDocumentModified();
1124 			if(pDoc->GetDrawLayer())
1125 				pDoc->GetDrawLayer()->SetDefaultTabulator(nTabDist);
1126 		}
1127 	}
1128 
1129 	//	AutoSpell nach den Doc-Options (weil Member)
1130 
1131 	if ( IS_AVAILABLE(SID_AUTOSPELL_CHECK,pItem) )				// an Doc-Options
1132 	{
1133 		sal_Bool bDoAutoSpell = ((const SfxBoolItem*)pItem)->GetValue();
1134 
1135 		if (pDoc)
1136 		{
1137 			ScDocOptions aNewOpt = pDoc->GetDocOptions();
1138 			if ( aNewOpt.IsAutoSpell() != bDoAutoSpell )
1139 			{
1140 				aNewOpt.SetAutoSpell( bDoAutoSpell );
1141 				pDoc->SetDocOptions( aNewOpt );
1142 
1143 				if (bDoAutoSpell)
1144 					pDoc->SetOnlineSpellPos( ScAddress(0,0,0) );	// vorne anfangen
1145 				else
1146 				{
1147 					WaitObject aWait( pDocSh->GetActiveDialogParent() );
1148 					pDoc->RemoveAutoSpellObj();		//	Edit-Text-Objekte wieder zurueckwandeln
1149 				}
1150 
1151                 //#92038#; don't set document modified, because this flag is no longer saved
1152 //				pDocSh->SetDocumentModified();
1153 
1154 				bRepaint = sal_True;			//	weil HideAutoSpell evtl. ungueltig
1155 											//!	alle Views painten ???
1156 			}
1157 		}
1158 
1159 		if ( bOldAutoSpell != bDoAutoSpell )
1160 		{
1161 			SetAutoSpellProperty( bDoAutoSpell );
1162 			bSaveSpellCheck = sal_True;
1163 		}
1164 		if ( pDocSh )
1165 			pDocSh->PostPaintGridAll();						// wegen Markierungen
1166 		ScInputHandler* pInputHandler = GetInputHdl();
1167 		if ( pInputHandler )
1168 			pInputHandler->UpdateSpellSettings();			// EditEngine-Flags
1169 		if ( pViewSh )
1170 			pViewSh->UpdateDrawTextOutliner();				// EditEngine-Flags
1171 
1172 		if (pBindings)
1173 			pBindings->Invalidate( SID_AUTOSPELL_CHECK );
1174 	}
1175 
1176 	//============================================
1177 	// InputOptions
1178 	//============================================
1179 
1180 	if ( IS_AVAILABLE(SID_SC_INPUT_SELECTIONPOS,pItem) )
1181 	{
1182 		pInputCfg->SetMoveDir( ((const SfxUInt16Item*)pItem)->GetValue() );
1183 		bSaveInputOptions = sal_True;
1184 	}
1185 	if ( IS_AVAILABLE(SID_SC_INPUT_SELECTION,pItem) )
1186 	{
1187 		pInputCfg->SetMoveSelection( ((const SfxBoolItem*)pItem)->GetValue() );
1188 		bSaveInputOptions = sal_True;
1189 	}
1190 	if ( IS_AVAILABLE(SID_SC_INPUT_EDITMODE,pItem) )
1191 	{
1192 		pInputCfg->SetEnterEdit( ((const SfxBoolItem*)pItem)->GetValue() );
1193 		bSaveInputOptions = sal_True;
1194 	}
1195 	if ( IS_AVAILABLE(SID_SC_INPUT_FMT_EXPAND,pItem) )
1196 	{
1197 		pInputCfg->SetExtendFormat( ((const SfxBoolItem*)pItem)->GetValue() );
1198 		bSaveInputOptions = sal_True;
1199 	}
1200 	if ( IS_AVAILABLE(SID_SC_INPUT_RANGEFINDER,pItem) )
1201 	{
1202 		pInputCfg->SetRangeFinder( ((const SfxBoolItem*)pItem)->GetValue() );
1203 		bSaveInputOptions = sal_True;
1204 	}
1205 	if ( IS_AVAILABLE(SID_SC_INPUT_REF_EXPAND,pItem) )
1206 	{
1207 		pInputCfg->SetExpandRefs( ((const SfxBoolItem*)pItem)->GetValue() );
1208 		bSaveInputOptions = sal_True;
1209 	}
1210 	if ( IS_AVAILABLE(SID_SC_INPUT_MARK_HEADER,pItem) )
1211 	{
1212 		pInputCfg->SetMarkHeader( ((const SfxBoolItem*)pItem)->GetValue() );
1213 		bSaveInputOptions = sal_True;
1214 		bUpdateMarks = sal_True;
1215 	}
1216 	if ( IS_AVAILABLE(SID_SC_INPUT_TEXTWYSIWYG,pItem) )
1217 	{
1218 		sal_Bool bNew = ((const SfxBoolItem*)pItem)->GetValue();
1219 		if ( bNew != pInputCfg->GetTextWysiwyg() )
1220 		{
1221 			pInputCfg->SetTextWysiwyg( bNew );
1222 			bSaveInputOptions = sal_True;
1223 			bUpdateRefDev = sal_True;
1224 		}
1225 	}
1226     if( IS_AVAILABLE( SID_SC_INPUT_REPLCELLSWARN, pItem ) )
1227 	{
1228         pInputCfg->SetReplaceCellsWarn( ((const SfxBoolItem*)pItem)->GetValue() );
1229         bSaveInputOptions = sal_True;
1230 	}
1231 
1232 	//============================================
1233 	// PrintOptions
1234 	//============================================
1235 
1236 	if ( IS_AVAILABLE(SID_SCPRINTOPTIONS,pItem) )
1237 	{
1238 		const ScPrintOptions& rNewOpt = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
1239 		SetPrintOptions( rNewOpt );
1240 
1241 		//	broadcast causes all previews to recalc page numbers
1242 		SFX_APP()->Broadcast( SfxSimpleHint( SID_SCPRINTOPTIONS ) );
1243 	}
1244 
1245 	//----------------------------------------------------------
1246 
1247 //	if ( bSaveSpellCheck )
1248 //	{
1249 		//	currently LinguProperties are saved only at program exit.
1250 		//	if a save method becomes available, it should be called here.
1251 //	}
1252 
1253 	if ( bSaveAppOptions )
1254 		pAppCfg->OptionsChanged();
1255 
1256 	if ( bSaveInputOptions )
1257 		pInputCfg->OptionsChanged();
1258 
1259 	// Neuberechnung anstossen?
1260 
1261 	if ( pDoc && bCalcAll )
1262 	{
1263 		WaitObject aWait( pDocSh->GetActiveDialogParent() );
1264 		pDoc->CalcAll();
1265         if ( pViewSh )
1266             pViewSh->UpdateCharts( sal_True );
1267         else
1268             ScDBFunc::DoUpdateCharts( ScAddress(), pDoc, sal_True );
1269 		if (pBindings)
1270 			pBindings->Invalidate( SID_ATTR_SIZE ); //SvxPosSize-StatusControl-Update
1271 	}
1272 
1273 	if ( pViewSh && bUpdateMarks )
1274 		pViewSh->UpdateAutoFillMark();
1275 
1276 	// View neuzeichnen?
1277 
1278 	if ( pViewSh && bRepaint )
1279 	{
1280 		pViewSh->UpdateFixPos();
1281 		pViewSh->PaintGrid();
1282 		pViewSh->PaintTop();
1283 		pViewSh->PaintLeft();
1284 		pViewSh->PaintExtras();
1285 		pViewSh->InvalidateBorder();
1286 		if (pBindings)
1287 		{
1288 			pBindings->Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
1289 			pBindings->Invalidate( FID_TOGGLESYNTAX );
1290 		}
1291 	}
1292 
1293 	// update ref device (for all documents)
1294 
1295 	if ( bUpdateRefDev )
1296 	{
1297 		//	for all documents: recalc output factor, update row heights
1298 		SfxObjectShell*	pObjSh = SfxObjectShell::GetFirst();
1299 		while ( pObjSh )
1300 		{
1301 			if ( pObjSh->Type() == TYPE(ScDocShell) )
1302 			{
1303                 ScDocShell* pOneDocSh = ((ScDocShell*)pObjSh);
1304                 pOneDocSh->CalcOutputFactor();
1305                 SCTAB nTabCount = pOneDocSh->GetDocument()->GetTableCount();
1306 				for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1307                     pOneDocSh->AdjustRowHeight( 0, MAXROW, nTab );
1308 			}
1309 			pObjSh = SfxObjectShell::GetNext( *pObjSh );
1310 		}
1311 
1312 		//	for all (tab-) views:
1313 		TypeId aScType = TYPE(ScTabViewShell);
1314 		SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
1315 		while ( pSh )
1316 		{
1317             ScTabViewShell* pOneViewSh = (ScTabViewShell*)pSh;
1318 
1319 			//	set ref-device for EditEngine
1320             ScInputHandler* pHdl = GetInputHdl(pOneViewSh);
1321 			if (pHdl)
1322 				pHdl->UpdateRefDevice();
1323 
1324 			//	update view scale
1325             ScViewData* pViewData = pOneViewSh->GetViewData();
1326             pOneViewSh->SetZoom( pViewData->GetZoomX(), pViewData->GetZoomY(), sal_False );
1327 
1328 			//	repaint
1329             pOneViewSh->PaintGrid();
1330             pOneViewSh->PaintTop();
1331             pOneViewSh->PaintLeft();
1332 
1333 			pSh = SfxViewShell::GetNext( *pSh, &aScType );
1334 		}
1335 	}
1336 }
1337 
1338 #undef IS_AVAILABLE
1339 
1340 //------------------------------------------------------------------
1341 //
1342 //						Input-Handler
1343 //
1344 //------------------------------------------------------------------
1345 
1346 ScInputHandler* ScModule::GetInputHdl( ScTabViewShell* pViewSh, sal_Bool bUseRef )
1347 {
1348 	if ( pRefInputHandler && bUseRef )
1349 		return pRefInputHandler;
1350 
1351 	ScInputHandler* pHdl = NULL;
1352 	if ( !pViewSh )
1353     {
1354         // in case a UIActive embedded object has no ViewShell ( UNO component )
1355         // the own calc view shell will be set as current, but no handling should happen
1356 
1357 		ScTabViewShell* pCurViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
1358         if ( pCurViewSh && !pCurViewSh->GetUIActiveClient() )
1359             pViewSh = pCurViewSh;
1360     }
1361 
1362 	if ( pViewSh )
1363 		pHdl = pViewSh->GetInputHandler();		// Viewshell hat jetzt immer einen
1364 
1365 	//	#57989# wenn keine ViewShell uebergeben oder aktiv, kann NULL herauskommen
1366 	DBG_ASSERT( pHdl || !pViewSh, "GetInputHdl: kein InputHandler gefunden" );
1367 	return pHdl;
1368 }
1369 
1370 void ScModule::ViewShellChanged()
1371 {
1372 	ScInputHandler* pHdl   = GetInputHdl();
1373 	ScTabViewShell* pShell = ScTabViewShell::GetActiveViewShell();
1374 	if ( pShell && pHdl )
1375 		pShell->UpdateInputHandler();
1376 }
1377 
1378 void ScModule::SetInputMode( ScInputMode eMode )
1379 {
1380 	ScInputHandler* pHdl = GetInputHdl();
1381 	if (pHdl)
1382 		pHdl->SetMode( eMode );
1383 }
1384 
1385 sal_Bool ScModule::IsEditMode()
1386 {
1387 	ScInputHandler* pHdl = GetInputHdl();
1388 	return pHdl && pHdl->IsEditMode();
1389 }
1390 
1391 sal_Bool ScModule::IsInputMode()
1392 {
1393 	ScInputHandler* pHdl = GetInputHdl();
1394 	return pHdl && pHdl->IsInputMode();
1395 }
1396 
1397 sal_Bool ScModule::InputKeyEvent( const KeyEvent& rKEvt, sal_Bool bStartEdit )
1398 {
1399 	ScInputHandler* pHdl = GetInputHdl();
1400 	return ( pHdl ? pHdl->KeyInput( rKEvt, bStartEdit ) : sal_False );
1401 }
1402 
1403 void ScModule::InputEnterHandler( sal_uInt8 nBlockMode )
1404 {
1405 	if ( !SFX_APP()->IsDowning() )									// nicht beim Programmende
1406 	{
1407 		ScInputHandler* pHdl = GetInputHdl();
1408 		if (pHdl)
1409 			pHdl->EnterHandler( nBlockMode );
1410 	}
1411 }
1412 
1413 void ScModule::InputCancelHandler()
1414 {
1415 	ScInputHandler* pHdl = GetInputHdl();
1416 	if (pHdl)
1417 		pHdl->CancelHandler();
1418 }
1419 
1420 void ScModule::InputSelection( EditView* pView )
1421 {
1422 	ScInputHandler* pHdl = GetInputHdl();
1423 	if (pHdl)
1424 		pHdl->InputSelection( pView );
1425 }
1426 
1427 void ScModule::InputChanged( EditView* pView )
1428 {
1429 	ScInputHandler* pHdl = GetInputHdl();
1430 	if (pHdl)
1431 		pHdl->InputChanged( pView );
1432 }
1433 
1434 void ScModule::ViewShellGone( ScTabViewShell* pViewSh )
1435 {
1436 	ScInputHandler* pHdl = GetInputHdl();
1437 	if (pHdl)
1438 		pHdl->ViewShellGone( pViewSh );
1439 }
1440 
1441 void ScModule::SetRefInputHdl( ScInputHandler* pNew )
1442 {
1443 	pRefInputHandler = pNew;
1444 }
1445 
1446 ScInputHandler* ScModule::GetRefInputHdl()
1447 {
1448 	return pRefInputHandler;
1449 }
1450 
1451 //------------------------------------------------------------------------
1452 //	Olk's Krempel:
1453 
1454 void ScModule::InputGetSelection( xub_StrLen& rStart, xub_StrLen& rEnd )
1455 {
1456 	ScInputHandler* pHdl = GetInputHdl();
1457 	if (pHdl)
1458 		pHdl->InputGetSelection( rStart, rEnd );
1459 }
1460 
1461 void ScModule::InputSetSelection( xub_StrLen nStart, xub_StrLen nEnd )
1462 {
1463 	ScInputHandler* pHdl = GetInputHdl();
1464 	if (pHdl)
1465 		pHdl->InputSetSelection( nStart, nEnd );
1466 }
1467 
1468 void ScModule::InputReplaceSelection( const String& rStr )
1469 {
1470 	ScInputHandler* pHdl = GetInputHdl();
1471 	if (pHdl)
1472 		pHdl->InputReplaceSelection( rStr );
1473 }
1474 
1475 String ScModule::InputGetFormulaStr()
1476 {
1477 	ScInputHandler* pHdl = GetInputHdl();
1478 	String aStr;
1479 	if ( pHdl )
1480 		aStr = pHdl->InputGetFormulaStr();
1481 	return aStr;
1482 }
1483 
1484 void ScModule::ActivateInputWindow( const String* pStrFormula, sal_Bool bMatrix )
1485 {
1486 	ScInputHandler* pHdl = GetInputHdl();
1487 	if ( pHdl )
1488 	{
1489 		ScInputWindow* pWin = pHdl->GetInputWindow();
1490 		if ( pStrFormula )
1491 		{
1492 			// Formel uebernehmen
1493 			if ( pWin )
1494 			{
1495 				pWin->SetFuncString( *pStrFormula, sal_False );
1496 				// SetSumAssignMode wegen sal_False nicht noetig
1497 			}
1498 			sal_uInt8 nMode = bMatrix ? SC_ENTER_MATRIX : SC_ENTER_NORMAL;
1499 			pHdl->EnterHandler( nMode );
1500 
1501 			//	ohne Invalidate bleibt die Selektion stehen, wenn die Formel unveraendert ist
1502 			if (pWin)
1503 				pWin->TextInvalidate();
1504 		}
1505 		else
1506 		{
1507 			// Abbrechen
1508 			if ( pWin )
1509 			{
1510 				pWin->SetFuncString( EMPTY_STRING, sal_False );
1511 				// SetSumAssignMode wegen sal_False nicht noetig
1512 			}
1513 			pHdl->CancelHandler();
1514 		}
1515 	}
1516 }
1517 
1518 //------------------------------------------------------------------
1519 //
1520 //					Referenz - Dialoge
1521 //
1522 //------------------------------------------------------------------
1523 
1524 void ScModule::SetRefDialog( sal_uInt16 nId, sal_Bool bVis, SfxViewFrame* pViewFrm )
1525 {
1526 	//!	move reference dialog handling to view
1527 	//!	(only keep function autopilot here for references to other documents)
1528 
1529 	if(nCurRefDlgId==0 || (nId==nCurRefDlgId && !bVis))
1530 	{
1531 		if ( !pViewFrm )
1532 			pViewFrm = SfxViewFrame::Current();
1533 
1534 		// #79379# bindings update causes problems with update of stylist if
1535 		// current style family has changed
1536 		//if ( pViewFrm )
1537 		//	pViewFrm->GetBindings().Update();		// to avoid trouble in LockDispatcher
1538 
1539 		nCurRefDlgId = bVis ? nId : 0 ;				// before SetChildWindow
1540 
1541 		if ( pViewFrm )
1542 		{
1543 			//	store the dialog id also in the view shell
1544 			SfxViewShell* pViewSh = pViewFrm->GetViewShell();
1545 			if ( pViewSh && pViewSh->ISA( ScTabViewShell ) )
1546 				((ScTabViewShell*)pViewSh)->SetCurRefDlgId( nCurRefDlgId );
1547             else
1548             {
1549                 // no ScTabViewShell - possible for example from a Basic macro
1550                 bVis = sal_False;
1551                 nCurRefDlgId = 0;   // don't set nCurRefDlgId if no dialog is created
1552             }
1553 
1554 			pViewFrm->SetChildWindow( nId, bVis );
1555 		}
1556 
1557 		SfxApplication* pSfxApp = SFX_APP();
1558 		pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) );
1559 	}
1560 }
1561 
1562 SfxChildWindow* lcl_GetChildWinFromAnyView( sal_uInt16 nId )
1563 {
1564 	//	first try the current view
1565 
1566 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1567     // #i46999# current view frame can be null (for example, when closing help)
1568     SfxChildWindow* pChildWnd = pViewFrm ? pViewFrm->GetChildWindow( nId ) : NULL;
1569 	if ( pChildWnd )
1570 		return pChildWnd;			// found in the current view
1571 
1572 	//	if not found there, get the child window from any open view
1573 	//	it can be open only in one view because nCurRefDlgId is global
1574 
1575 	pViewFrm = SfxViewFrame::GetFirst();
1576 	while ( pViewFrm )
1577 	{
1578 		pChildWnd = pViewFrm->GetChildWindow( nId );
1579 		if ( pChildWnd )
1580 			return pChildWnd;		// found in any view
1581 
1582 		pViewFrm = SfxViewFrame::GetNext( *pViewFrm );
1583 	}
1584 
1585 	return NULL;					// none found
1586 }
1587 
1588 sal_Bool ScModule::IsModalMode(SfxObjectShell* pDocSh)
1589 {
1590 	//!	move reference dialog handling to view
1591 	//!	(only keep function autopilot here for references to other documents)
1592 
1593 	sal_Bool bIsModal = sal_False;
1594 
1595 	if ( nCurRefDlgId )
1596 	{
1597 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1598 		if ( pChildWnd )
1599 		{
1600 			IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1601 			bIsModal = pChildWnd->IsVisible() &&
1602 				!( pRefDlg->IsRefInputMode() && pRefDlg->IsDocAllowed(pDocSh) );
1603 		}
1604 		else
1605 		{
1606 			// in 592 and above, the dialog isn't visible in other views
1607 			//	if the dialog is open but can't be accessed, disable input
1608 
1609 			bIsModal = sal_True;
1610 		}
1611 
1612 		//	pChildWnd kann 0 sein, wenn der Dialog nach dem Umschalten
1613 		//	von einer anderen Shell noch nicht erzeugt wurde (z.B. in GetFocus)
1614 	}
1615 	else if (pDocSh)
1616 	{
1617 		ScInputHandler* pHdl = GetInputHdl();
1618 		if ( pHdl )
1619 			bIsModal = pHdl->IsModalMode(pDocSh);
1620 	}
1621 
1622 	return bIsModal;
1623 }
1624 
1625 sal_Bool ScModule::IsTableLocked()
1626 {
1627 	//!	move reference dialog handling to view
1628 	//!	(only keep function autopilot here for references to other documents)
1629 
1630 	sal_Bool bLocked = sal_False;
1631 
1632 	//	bisher nur bei ScAnyRefDlg
1633 
1634 	if ( nCurRefDlgId )
1635 	{
1636 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1637 		if ( pChildWnd )
1638 			bLocked = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow())->IsTableLocked();
1639 		else
1640 			bLocked = sal_True;		// for other views, see IsModalMode
1641 	}
1642 
1643 	return bLocked;
1644 }
1645 
1646 sal_Bool ScModule::IsRefDialogOpen()
1647 {
1648 	//!	move reference dialog handling to view
1649 	//!	(only keep function autopilot here for references to other documents)
1650 
1651 	sal_Bool bIsOpen = sal_False;
1652 
1653 	if ( nCurRefDlgId )
1654 	{
1655 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1656 		if ( pChildWnd )
1657 			bIsOpen = pChildWnd->IsVisible();
1658 		else
1659 			bIsOpen = sal_True;		// for other views, see IsModalMode
1660 	}
1661 
1662 	return bIsOpen;
1663 }
1664 
1665 sal_Bool ScModule::IsFormulaMode()
1666 {
1667 	//!	move reference dialog handling to view
1668 	//!	(only keep function autopilot here for references to other documents)
1669 
1670 	sal_Bool bIsFormula = sal_False;
1671 
1672 	if ( nCurRefDlgId )
1673 	{
1674 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1675 		if ( pChildWnd )
1676 		{
1677 			IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1678 			bIsFormula = pChildWnd->IsVisible() && pRefDlg->IsRefInputMode();
1679 		}
1680 	}
1681 	else
1682 	{
1683 		ScInputHandler* pHdl = GetInputHdl();
1684 		if ( pHdl )
1685 			bIsFormula = pHdl->IsFormulaMode();
1686 	}
1687 
1688 	if (bIsInEditCommand)
1689 		bIsFormula = sal_True;
1690 
1691 	return bIsFormula;
1692 }
1693 
1694 void lcl_MarkedTabs( const ScMarkData& rMark, SCTAB& rStartTab, SCTAB& rEndTab )
1695 {
1696 	if (rMark.GetSelectCount() > 1)
1697 	{
1698 		sal_Bool bFirst = sal_True;
1699 		for (SCTAB i=0; i<=MAXTAB; i++)
1700 			if (rMark.GetTableSelect(i))
1701 			{
1702 				if (bFirst)
1703 					rStartTab = i;
1704 				rEndTab = i;
1705 				bFirst = sal_False;
1706 			}
1707 	}
1708 }
1709 
1710 void ScModule::SetReference( const ScRange& rRef, ScDocument* pDoc,
1711 									const ScMarkData* pMarkData )
1712 {
1713 	//!	move reference dialog handling to view
1714 	//!	(only keep function autopilot here for references to other documents)
1715 
1716 	//	in Ref-Dialogen wird hiermit auch das Zoom-In ausgeloest,
1717 	//	wenn Start und Ende der Ref unterschiedlich sind
1718 
1719 	ScRange aNew = rRef;
1720 	aNew.Justify();					// immer "richtig herum"
1721 
1722 	if( nCurRefDlgId )
1723 	{
1724 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1725 		DBG_ASSERT( pChildWnd, "NoChildWin" );
1726 		if ( pChildWnd )
1727 		{
1728 			if ( nCurRefDlgId == SID_OPENDLG_CONSOLIDATE && pMarkData )
1729 			{
1730 				SCTAB nStartTab = aNew.aStart.Tab();
1731 				SCTAB nEndTab   = aNew.aEnd.Tab();
1732 				lcl_MarkedTabs( *pMarkData, nStartTab, nEndTab );
1733 				aNew.aStart.SetTab(nStartTab);
1734 				aNew.aEnd.SetTab(nEndTab);
1735 			}
1736 
1737 			IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1738 
1739 			//	hide the (color) selection now instead of later from LoseFocus,
1740 			//	don't abort the ref input that causes this call (bDoneRefMode = sal_False)
1741 			pRefDlg->HideReference( sal_False );
1742 			pRefDlg->SetReference( aNew, pDoc );
1743 		}
1744 	}
1745 	else
1746 	{
1747 		ScInputHandler* pHdl = GetInputHdl();
1748 		if (pHdl)
1749 			pHdl->SetReference( aNew, pDoc );
1750 		else
1751 		{
1752 			DBG_ERROR("SetReference ohne Empfaenger");
1753 		}
1754 	}
1755 }
1756 
1757 void ScModule::AddRefEntry()						// "Mehrfachselektion"
1758 {
1759 	//!	move reference dialog handling to view
1760 	//!	(only keep function autopilot here for references to other documents)
1761 
1762 	if ( nCurRefDlgId )
1763 	{
1764 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1765 		DBG_ASSERT( pChildWnd, "NoChildWin" );
1766 		if ( pChildWnd )
1767 		{
1768 			IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1769 			pRefDlg->AddRefEntry();
1770 		}
1771 	}
1772 	else
1773 	{
1774 		ScInputHandler* pHdl = GetInputHdl();
1775 		if (pHdl)
1776 			pHdl->AddRefEntry();
1777 	}
1778 }
1779 
1780 void ScModule::EndReference()
1781 {
1782 	//!	move reference dialog handling to view
1783 	//!	(only keep function autopilot here for references to other documents)
1784 
1785 	//	in Ref-Dialogen wird hiermit auch das Zoom-In wieder aufgehoben
1786 
1787 	//!	ShowRefFrame am InputHdl, wenn der Funktions-AP offen ist ???
1788 
1789 	if ( nCurRefDlgId )
1790 	{
1791 		SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
1792 		DBG_ASSERT( pChildWnd, "NoChildWin" );
1793 		if ( pChildWnd )
1794 		{
1795 			IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
1796 			pRefDlg->SetActive();
1797 		}
1798 	}
1799 }
1800 
1801 //------------------------------------------------------------------
1802 //
1803 //					Idle / Online-Spelling
1804 //
1805 //------------------------------------------------------------------
1806 
1807 void ScModule::AnythingChanged()
1808 {
1809 	sal_uLong nOldTime = aIdleTimer.GetTimeout();
1810 	if ( nOldTime != SC_IDLE_MIN )
1811 		aIdleTimer.SetTimeout( SC_IDLE_MIN );
1812 
1813 	nIdleCount = 0;
1814 }
1815 
1816 void lcl_CheckNeedsRepaint( ScDocShell* pDocShell )
1817 {
1818 	SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
1819 	while ( pFrame )
1820 	{
1821 		SfxViewShell* p = pFrame->GetViewShell();
1822 		ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
1823 		if ( pViewSh )
1824 			pViewSh->CheckNeedsRepaint();
1825 		pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
1826 	}
1827 }
1828 
1829 IMPL_LINK( ScModule, IdleHandler, Timer*, EMPTYARG )
1830 {
1831 	if ( Application::AnyInput( INPUT_MOUSEANDKEYBOARD ) )
1832 	{
1833 		aIdleTimer.Start();			// Timeout unveraendert
1834 		return 0;
1835 	}
1836 
1837 	sal_Bool bMore = sal_False;
1838 	ScDocShell* pDocSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
1839 	if ( pDocSh )
1840 	{
1841 		ScDocument* pDoc = pDocSh->GetDocument();
1842 
1843         sal_Bool bLinks = pDoc->IdleCheckLinks();
1844         sal_Bool bWidth = pDoc->IdleCalcTextWidth();
1845         sal_Bool bSpell = pDoc->ContinueOnlineSpelling();
1846         if ( bSpell )
1847             aSpellTimer.Start();					// da ist noch was
1848 
1849         bMore = bLinks || bWidth || bSpell;			// ueberhaupt noch was?
1850 
1851         //	While calculating a Basic formula, a paint event may have occured,
1852         //	so check the bNeedsRepaint flags for this document's views
1853         if (bWidth)
1854             lcl_CheckNeedsRepaint( pDocSh );
1855 	}
1856 
1857 	sal_uLong nOldTime = aIdleTimer.GetTimeout();
1858 	sal_uLong nNewTime = nOldTime;
1859 	if ( bMore )
1860 	{
1861 		nNewTime = SC_IDLE_MIN;
1862 		nIdleCount = 0;
1863 	}
1864 	else
1865 	{
1866 		//	SC_IDLE_COUNT mal mit initialem Timeout, dann hochzaehlen
1867 
1868 		if ( nIdleCount < SC_IDLE_COUNT )
1869 			++nIdleCount;
1870 		else
1871 		{
1872 			nNewTime += SC_IDLE_STEP;
1873 			if ( nNewTime > SC_IDLE_MAX )
1874 				nNewTime = SC_IDLE_MAX;
1875 		}
1876 	}
1877 	if ( nNewTime != nOldTime )
1878 		aIdleTimer.SetTimeout( nNewTime );
1879 
1880 	aIdleTimer.Start();
1881 	return 0;
1882 }
1883 
1884 IMPL_LINK( ScModule, SpellTimerHdl, Timer*, EMPTYARG )
1885 {
1886 	if ( Application::AnyInput( INPUT_KEYBOARD ) )
1887 	{
1888 		aSpellTimer.Start();
1889 		return 0;					// dann spaeter wieder...
1890 	}
1891 
1892 	ScDocShell* pDocSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
1893 	if ( pDocSh )
1894 	{
1895 		ScDocument* pDoc = pDocSh->GetDocument();
1896 		if ( pDoc->ContinueOnlineSpelling() )
1897 			aSpellTimer.Start();
1898 	}
1899 	return 0;
1900 }
1901 
1902 	//virtuelle Methoden fuer den Optionendialog
1903 SfxItemSet*	 ScModule::CreateItemSet( sal_uInt16 nId )
1904 {
1905 	SfxItemSet*	 pRet = 0;
1906 	if(SID_SC_EDITOPTIONS == nId)
1907 	{
1908 		pRet = new SfxItemSet( GetPool(),
1909 							// TP_CALC:
1910 							SID_SCDOCOPTIONS,		SID_SCDOCOPTIONS,
1911 							// TP_VIEW:
1912 							SID_SCVIEWOPTIONS,		SID_SCVIEWOPTIONS,
1913                             SID_SC_OPT_SYNCZOOM,    SID_SC_OPT_SYNCZOOM,
1914 							// TP_INPUT:
1915 							SID_SC_INPUT_SELECTION,SID_SC_INPUT_MARK_HEADER,
1916 							SID_SC_INPUT_TEXTWYSIWYG,SID_SC_INPUT_TEXTWYSIWYG,
1917                             SID_SC_INPUT_REPLCELLSWARN,SID_SC_INPUT_REPLCELLSWARN,
1918 							// TP_USERLISTS:
1919 							SCITEM_USERLIST,		SCITEM_USERLIST,
1920 							// TP_PRINT:
1921 							SID_SCPRINTOPTIONS,	SID_SCPRINTOPTIONS,
1922 							// TP_GRID:
1923 							SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
1924 							//
1925 							SID_ATTR_METRIC,		SID_ATTR_METRIC,
1926 							SID_ATTR_DEFTABSTOP,	SID_ATTR_DEFTABSTOP,
1927 							0 );
1928 
1929 		ScDocShell* 	pDocSh = PTR_CAST(ScDocShell,
1930 											SfxObjectShell::Current());
1931 		ScDocOptions	aCalcOpt = pDocSh
1932 							? pDocSh->GetDocument()->GetDocOptions()
1933 							: GetDocOptions();
1934 
1935 		ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,
1936 											SfxViewShell::Current());
1937 		ScViewOptions	aViewOpt = pViewSh
1938 							? pViewSh->GetViewData()->GetOptions()
1939 							: GetViewOptions();
1940 
1941 		ScUserListItem	aULItem( SCITEM_USERLIST );
1942 		ScUserList* 	pUL = ScGlobal::GetUserList();
1943 
1944         //  SFX_APP()->GetOptions( aSet );
1945 
1946 		pRet->Put( SfxUInt16Item( SID_ATTR_METRIC,
1947                         sal::static_int_cast<sal_uInt16>(GetAppOptions().GetAppMetric()) ) );
1948 
1949 		// TP_CALC
1950 		pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP,
1951 						aCalcOpt.GetTabDistance()));
1952 		pRet->Put( ScTpCalcItem( SID_SCDOCOPTIONS, aCalcOpt ) );
1953 
1954 		// TP_VIEW
1955 		pRet->Put( ScTpViewItem( SID_SCVIEWOPTIONS, aViewOpt ) );
1956         pRet->Put( SfxBoolItem( SID_SC_OPT_SYNCZOOM, GetAppOptions().GetSynchronizeZoom() ) );
1957 
1958 		// TP_INPUT
1959 		const ScInputOptions& rInpOpt = GetInputOptions();
1960 		pRet->Put( SfxUInt16Item( SID_SC_INPUT_SELECTIONPOS,
1961 					rInpOpt.GetMoveDir() ) );
1962 		pRet->Put( SfxBoolItem( SID_SC_INPUT_SELECTION,
1963 					rInpOpt.GetMoveSelection() ) );
1964 		pRet->Put( SfxBoolItem( SID_SC_INPUT_EDITMODE,
1965 					rInpOpt.GetEnterEdit() ) );
1966 		pRet->Put( SfxBoolItem( SID_SC_INPUT_FMT_EXPAND,
1967 					rInpOpt.GetExtendFormat() ) );
1968 		pRet->Put( SfxBoolItem( SID_SC_INPUT_RANGEFINDER,
1969 					rInpOpt.GetRangeFinder() ) );
1970 		pRet->Put( SfxBoolItem( SID_SC_INPUT_REF_EXPAND,
1971 					rInpOpt.GetExpandRefs() ) );
1972 		pRet->Put( SfxBoolItem( SID_SC_INPUT_MARK_HEADER,
1973 					rInpOpt.GetMarkHeader() ) );
1974 		pRet->Put( SfxBoolItem( SID_SC_INPUT_TEXTWYSIWYG,
1975 					rInpOpt.GetTextWysiwyg() ) );
1976         pRet->Put( SfxBoolItem( SID_SC_INPUT_REPLCELLSWARN,
1977                     rInpOpt.GetReplaceCellsWarn() ) );
1978 
1979 		// RID_SC_TP_PRINT
1980 		pRet->Put( ScTpPrintItem( SID_SCPRINTOPTIONS, GetPrintOptions() ) );
1981 
1982 		// TP_GRID
1983 		SvxGridItem* pSvxGridItem = aViewOpt.CreateGridItem();
1984 		pRet->Put( *pSvxGridItem );
1985 		delete pSvxGridItem;
1986 
1987 		// TP_USERLISTS
1988 		if ( pUL )
1989 			aULItem.SetUserList( *pUL );
1990 		pRet->Put( aULItem );
1991 
1992 	}
1993 	return pRet;
1994 }
1995 
1996 void ScModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
1997 {
1998 	if(SID_SC_EDITOPTIONS == nId)
1999 	{
2000 		ModifyOptions( rSet );
2001 	}
2002 }
2003 
2004 SfxTabPage*	 ScModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
2005 {
2006 	SfxTabPage* pRet = NULL;
2007 	ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2008 	DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
2009 	switch(nId)
2010 	{
2011 		case SID_SC_TP_LAYOUT:
2012 								{
2013 									//CHINA001 pRet = ScTpLayoutOptions::Create(pParent, rSet);
2014 									::CreateTabPage ScTpLayoutOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_LAYOUT );
2015 									if ( ScTpLayoutOptionsCreate )
2016 										pRet =  (*ScTpLayoutOptionsCreate) (pParent, rSet);
2017 								}
2018 								break;
2019 		case SID_SC_TP_CONTENT:
2020 								{
2021 									//CHINA001 pRet = ScTpContentOptions::Create(pParent, rSet);
2022 									::CreateTabPage ScTpContentOptionsCreate = pFact->GetTabPageCreatorFunc(RID_SCPAGE_CONTENT);
2023 									if ( ScTpContentOptionsCreate )
2024 										pRet = (*ScTpContentOptionsCreate)(pParent, rSet);
2025 								}
2026 								break;
2027 		case SID_SC_TP_GRID: 	 		pRet = SvxGridTabPage::Create(pParent, rSet); break;
2028 		case SID_SC_TP_USERLISTS:
2029 								{
2030 									//CHINA001 pRet = ScTpUserLists::Create(pParent, rSet);
2031 									::CreateTabPage ScTpUserListsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_USERLISTS );
2032 									if ( ScTpUserListsCreate )
2033 											pRet = (*ScTpUserListsCreate)( pParent, rSet);
2034 								}
2035 								break;
2036 		case SID_SC_TP_CALC:
2037 								{	//CHINA001 pRet = ScTpCalcOptions::Create(pParent, rSet);
2038 													::CreateTabPage ScTpCalcOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_CALC );
2039 													if ( ScTpCalcOptionsCreate )
2040 														pRet = (*ScTpCalcOptionsCreate)(pParent, rSet);
2041 								}
2042 								break;
2043 		case SID_SC_TP_CHANGES:
2044 								{			//CHINA001 pRet = ScRedlineOptionsTabPage::Create(pParent, rSet);
2045 											::CreateTabPage ScRedlineOptionsTabPageCreate =	pFact->GetTabPageCreatorFunc( RID_SCPAGE_OPREDLINE );
2046 											if ( ScRedlineOptionsTabPageCreate )
2047 													pRet =(*ScRedlineOptionsTabPageCreate)(pParent, rSet);
2048 								}
2049 						break;
2050 		case RID_SC_TP_PRINT:
2051 								{//CHINA001 pRet = ScTpPrintOptions::Create(pParent, rSet);
2052 									::CreateTabPage ScTpPrintOptionsCreate = 	pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
2053 									if ( ScTpPrintOptionsCreate )
2054 										pRet = (*ScTpPrintOptionsCreate)( pParent, rSet);
2055 								}
2056 			break;
2057 		case RID_OFA_TP_INTERNATIONAL:
2058 		{
2059 			SfxAbstractDialogFactory* pSfxFact = SfxAbstractDialogFactory::Create();
2060 			if ( pSfxFact )
2061 			{
2062 				::CreateTabPage fnCreatePage = pSfxFact->GetTabPageCreatorFunc( nId );
2063 				if ( fnCreatePage )
2064 					pRet = (*fnCreatePage)( pParent, rSet );
2065 			}
2066 		}
2067 	}
2068 
2069 	DBG_ASSERT( pRet, "ScModule::CreateTabPage(): no valid ID for TabPage!" );
2070 
2071 	return pRet;
2072 }
2073 
2074 //------------------------------------------------------------------
2075 
2076 IMPL_LINK( ScModule, CalcFieldValueHdl, EditFieldInfo*, pInfo )
2077 {
2078 	//!	mit ScFieldEditEngine zusammenfassen !!!
2079 
2080 	if (pInfo)
2081 	{
2082 		const SvxFieldItem& rField = pInfo->GetField();
2083 		const SvxFieldData* pField = rField.GetField();
2084 
2085 		if (pField && pField->ISA(SvxURLField))
2086 		{
2087 			/******************************************************************
2088 			* URL-Field
2089 			******************************************************************/
2090 
2091 			const SvxURLField* pURLField = (const SvxURLField*) pField;
2092 			String aURL = pURLField->GetURL();
2093 
2094 			switch ( pURLField->GetFormat() )
2095 			{
2096 				case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
2097 				case SVXURLFORMAT_REPR:
2098 				{
2099 					pInfo->SetRepresentation( pURLField->GetRepresentation() );
2100 				}
2101 				break;
2102 
2103 				case SVXURLFORMAT_URL:
2104 				{
2105 					pInfo->SetRepresentation( aURL );
2106 				}
2107 				break;
2108 			}
2109 
2110             svtools::ColorConfigEntry eEntry =
2111                 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
2112 			pInfo->SetTxtColor( GetColorConfig().GetColorValue(eEntry).nColor );
2113 		}
2114 		else
2115 		{
2116 			DBG_ERROR("unbekannter Feldbefehl");
2117 			pInfo->SetRepresentation(String('?'));
2118 		}
2119 	}
2120 
2121 	return 0;
2122 }
2123 
2124 sal_Bool ScModule::RegisterRefWindow( sal_uInt16 nSlotId, Window *pWnd )
2125 {
2126     std::list<Window*> & rlRefWindow = m_mapRefWindow[nSlotId];
2127 
2128     if( std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd ) == rlRefWindow.end() )
2129     {
2130         rlRefWindow.push_back( pWnd );
2131         return sal_True;
2132     }
2133 
2134     return sal_False;
2135 }
2136 
2137 sal_Bool  ScModule::UnregisterRefWindow( sal_uInt16 nSlotId, Window *pWnd )
2138 {
2139     std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2140 
2141     if( iSlot == m_mapRefWindow.end() )
2142         return sal_False;
2143 
2144     std::list<Window*> & rlRefWindow = iSlot->second;
2145 
2146     std::list<Window*>::iterator i = std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd );
2147 
2148     if( i == rlRefWindow.end() )
2149         return sal_False;
2150 
2151     rlRefWindow.erase( i );
2152 
2153     if( !rlRefWindow.size() )
2154         m_mapRefWindow.erase( nSlotId );
2155 
2156     return sal_True;
2157 }
2158 
2159 sal_Bool  ScModule::IsAliveRefDlg( sal_uInt16 nSlotId, Window *pWnd )
2160 {
2161     std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2162 
2163     if( iSlot == m_mapRefWindow.end() )
2164         return sal_False;
2165 
2166     std::list<Window*> & rlRefWindow = iSlot->second;
2167 
2168     return rlRefWindow.end() != std::find( rlRefWindow.begin(), rlRefWindow.end(), pWnd );
2169 }
2170 
2171 Window *  ScModule::Find1RefWindow( sal_uInt16 nSlotId, Window *pWndAncestor )
2172 {
2173     if (!pWndAncestor)
2174         return NULL;
2175 
2176     std::map<sal_uInt16, std::list<Window*> >::iterator iSlot = m_mapRefWindow.find( nSlotId );
2177 
2178     if( iSlot == m_mapRefWindow.end() )
2179         return NULL;
2180 
2181     std::list<Window*> & rlRefWindow = iSlot->second;
2182 
2183     while( Window *pParent = pWndAncestor->GetParent() ) pWndAncestor = pParent;
2184 
2185     for( std::list<Window*>::iterator i = rlRefWindow.begin(); i!=rlRefWindow.end(); i++ )
2186         if ( pWndAncestor->IsWindowOrChild( *i, (*i)->IsSystemWindow() ) )
2187             return *i;
2188 
2189     return NULL;
2190 }
2191 
2192 Window *  ScModule::Find1RefWindow( Window *pWndAncestor )
2193 {
2194     if (!pWndAncestor)
2195         return NULL;
2196 
2197     while( Window *pParent = pWndAncestor->GetParent() ) pWndAncestor = pParent;
2198 
2199     for( std::map<sal_uInt16, std::list<Window*> >::iterator i = m_mapRefWindow.begin();
2200         i!=m_mapRefWindow.end(); i++ )
2201         for( std::list<Window*>::iterator j = i->second.begin(); j!=i->second.end(); j++ )
2202             if ( pWndAncestor->IsWindowOrChild( *j, (*j)->IsSystemWindow() ) )
2203                 return *j;
2204 
2205     return NULL;
2206 }
2207 
2208