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