xref: /aoo41x/main/sc/source/ui/view/cellsh3.cxx (revision d9a8b508)
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 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 
31 #include "scitems.hxx"
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/request.hxx>
36 #include <svl/stritem.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <sfx2/app.hxx>
39 #include "globstr.hrc"
40 #include "scmod.hxx"
41 #include "appoptio.hxx"
42 #include "tabvwsh.hxx"
43 #include "document.hxx"
44 #include "sc.hrc"
45 #include "docsh.hxx"
46 #include "reffact.hxx"
47 #include "uiitems.hxx"
48 //CHINA001 #include "scendlg.hxx"
49 //CHINA001 #include "mtrindlg.hxx"
50 #include "autoform.hxx"
51 #include "autofmt.hxx"
52 #include "cellsh.hxx"
53 #include "attrdlg.hrc"		// TP_ALIGNMENT
54 #include "inputhdl.hxx"
55 #include "editable.hxx"
56 
57 #include "scabstdlg.hxx" //CHINA001
58 
59 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
60 
61 inline long TwipsToHMM(long nTwips)	{ return (nTwips * 127 + 36) / 72; }
62 inline long HMMToTwips(long nHMM)	{ return (nHMM * 72 + 63) / 127; }
63 inline long TwipsToEvenHMM(long nTwips)	{ return ( (nTwips * 127 + 72) / 144 ) * 2; }
64 
65 //------------------------------------------------------------------
66 
67 void ScCellShell::Execute( SfxRequest& rReq )
68 {
69 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
70 	SfxBindings&		rBindings	= pTabViewShell->GetViewFrame()->GetBindings();
71 	ScModule*			pScMod		= SC_MOD();
72 	const SfxItemSet*	pReqArgs	= rReq.GetArgs();
73 	sal_uInt16				nSlot		= rReq.GetSlot();
74 
75 	if (nSlot != SID_CURRENTCELL)		// der kommt beim MouseButtonUp
76 		pTabViewShell->HideListBox();	// Autofilter-DropDown-Listbox
77 
78 	if ( IS_EDITMODE() )
79 	{
80 		switch ( nSlot )
81 		{
82 			//	beim Oeffnen eines Referenz-Dialogs darf die SubShell nicht umgeschaltet werden
83 			//	(beim Schliessen des Dialogs wird StopEditShell gerufen)
84 			case SID_OPENDLG_FUNCTION:
85 					//	#53318# inplace macht die EditShell Aerger...
86 					//!	kann nicht immer umgeschaltet werden ????
87                     if (!pTabViewShell->GetViewFrame()->GetFrame().IsInPlace())
88 						pTabViewShell->SetDontSwitch(sal_True);			// EditShell nicht abschalten
89 					// kein break
90 
91 			case FID_CELL_FORMAT:
92 			case SID_ENABLE_HYPHENATION:
93 			case SID_DATA_SELECT:
94 			case SID_OPENDLG_CONSOLIDATE:
95 			case SID_OPENDLG_SOLVE:
96             case SID_OPENDLG_OPTSOLVER:
97 
98 					pScMod->InputEnterHandler();
99 					pTabViewShell->UpdateInputHandler();
100 
101 					pTabViewShell->SetDontSwitch(sal_False);
102 
103 					break;
104 
105 			default:
106 					break;
107 		}
108 	}
109 
110 	switch ( nSlot )
111 	{
112 
113 
114 
115 		case SID_ATTR_SIZE://XXX ???
116 			break;
117 
118 		case SID_STATUS_SELMODE:
119 			if ( pReqArgs )
120 			{
121 				/* 0: STD	Click hebt Sel auf
122 				 * 1: ER	Click erweitert Selektion
123 				 * 2: ERG	Click definiert weitere Selektion
124 				 */
125 				sal_uInt16 nMode = ((const SfxUInt16Item&)pReqArgs->Get( nSlot )).GetValue();
126 
127 				switch ( nMode )
128 				{
129 					case 1: nMode = KEY_SHIFT;	break;
130 					case 2: nMode = KEY_MOD1;	break; // Control-Taste
131 					case 0:
132 					default:
133 						nMode = 0;
134 				}
135 
136 				pTabViewShell->LockModifiers( nMode );
137 			}
138 			else
139 			{
140 				//	no arguments (also executed by double click on the status bar controller):
141 				//	advance to next selection mode
142 
143 				sal_uInt16 nModifiers = pTabViewShell->GetLockedModifiers();
144 				switch ( nModifiers )
145 				{
146 					case KEY_SHIFT:	nModifiers = KEY_MOD1;	break;		// EXT -> ADD
147 					case KEY_MOD1:	nModifiers = 0;			break;		// ADD -> STD
148 					default:		nModifiers = KEY_SHIFT;	break;		// STD -> EXT
149 				}
150 				pTabViewShell->LockModifiers( nModifiers );
151 			}
152 
153 			rBindings.Invalidate( SID_STATUS_SELMODE );
154 			rReq.Done();
155 			break;
156 
157 		//	SID_STATUS_SELMODE_NORM wird nicht benutzt ???
158 
159 		case SID_STATUS_SELMODE_NORM:
160 			pTabViewShell->LockModifiers( 0 );
161 			rBindings.Invalidate( SID_STATUS_SELMODE );
162 			break;
163 
164 		//	SID_STATUS_SELMODE_ERG / SID_STATUS_SELMODE_ERW als Toggles:
165 
166 		case SID_STATUS_SELMODE_ERG:
167 			if ( pTabViewShell->GetLockedModifiers() & KEY_MOD1 )
168 				pTabViewShell->LockModifiers( 0 );
169 			else
170 				pTabViewShell->LockModifiers( KEY_MOD1 );
171 			rBindings.Invalidate( SID_STATUS_SELMODE );
172 			break;
173 
174 		case SID_STATUS_SELMODE_ERW:
175 			if ( pTabViewShell->GetLockedModifiers() & KEY_SHIFT )
176 				pTabViewShell->LockModifiers( 0 );
177 			else
178 				pTabViewShell->LockModifiers( KEY_SHIFT );
179 			rBindings.Invalidate( SID_STATUS_SELMODE );
180 			break;
181 
182 		case SID_ENTER_STRING:
183 			{
184 				if ( pReqArgs )
185 				{
186 					String aStr( ((const SfxStringItem&)pReqArgs->
187 									Get( SID_ENTER_STRING )).GetValue() );
188 
189 					pTabViewShell->EnterData( GetViewData()->GetCurX(),
190 											   GetViewData()->GetCurY(),
191 											   GetViewData()->GetTabNo(),
192 											   aStr );
193 
194 					ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
195 					if ( !pHdl || !pHdl->IsInEnterHandler() )
196 					{
197 						//	#101061# UpdateInputHandler is needed after the cell content
198 						//	has changed, but if called from EnterHandler, UpdateInputHandler
199 						//	will be called later when moving the cursor.
200 
201 						pTabViewShell->UpdateInputHandler();
202 					}
203 
204 					rReq.Done();
205 
206 					//	hier kein GrabFocus, weil sonst auf dem Mac die Tabelle vor die
207 					//	Seitenansicht springt, wenn die Eingabe nicht abgeschlossen war
208 					//	(GrabFocus passiert in KillEditView)
209 				}
210 			}
211 			break;
212 
213 		case SID_INSERT_MATRIX:
214 			{
215 				if ( pReqArgs )
216 				{
217 					String aStr = ((const SfxStringItem&)pReqArgs->
218 									Get( SID_INSERT_MATRIX )).GetValue();
219 					pTabViewShell->EnterMatrix( aStr );
220 					rReq.Done();
221 				}
222 			}
223 			break;
224 
225 		case FID_INPUTLINE_ENTER:
226 		case FID_INPUTLINE_BLOCK:
227 		case FID_INPUTLINE_MATRIX:
228 			{
229 				if( pReqArgs == 0 ) //XXX vorlaufiger HACK um GPF zu vermeiden
230 					break;
231 
232 				const ScInputStatusItem* pStatusItem
233 					= (const ScInputStatusItem*)&pReqArgs->
234 							Get( FID_INPUTLINE_STATUS );
235 
236 				ScAddress aCursorPos = pStatusItem->GetPos();
237                 String aString = pStatusItem->GetString();
238 				const EditTextObject* pData = pStatusItem->GetEditData();
239 				if (pData)
240 				{
241 					if (nSlot == FID_INPUTLINE_BLOCK)
242                     {
243 						pTabViewShell->EnterBlock( aString, pData );
244                     }
245                     else if ( aString.Len() > 0 && ( aString.GetChar(0) == '=' || aString.GetChar(0) == '+' || aString.GetChar(0) == '-' ) )
246                     {
247                         pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, sal_True, pData );
248                     }
249 					else
250                     {
251 						pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), pData );
252                     }
253 				}
254 				else
255 				{
256 					if (nSlot == FID_INPUTLINE_ENTER)
257 					{
258 						if (
259 							aCursorPos.Col() == GetViewData()->GetCurX() &&
260 							aCursorPos.Row() == GetViewData()->GetCurY() &&
261 							aCursorPos.Tab() == GetViewData()->GetTabNo()
262 							)
263 						{
264 							SfxStringItem	aItem( SID_ENTER_STRING, aString );
265 
266                             // SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
267 							const SfxPoolItem* aArgs[2];
268 							aArgs[0] = &aItem;
269 							aArgs[1] = NULL;
270 							rBindings.Execute( SID_ENTER_STRING, aArgs );
271 						}
272 						else
273 						{
274 							pTabViewShell->EnterData( aCursorPos.Col(),
275 													aCursorPos.Row(),
276 													aCursorPos.Tab(),
277 													aString );
278 							rReq.Done();
279 						}
280 					}
281 					else if (nSlot == FID_INPUTLINE_BLOCK)
282 					{
283 						pTabViewShell->EnterBlock( aString, NULL );
284 						rReq.Done();
285 					}
286 					else
287 					{
288 						pTabViewShell->EnterMatrix( aString );
289 						rReq.Done();
290 					}
291 
292 				}
293 
294 				//	hier kein GrabFocus, weil sonst auf dem Mac die Tabelle vor die
295 				//	Seitenansicht springt, wenn die Eingabe nicht abgeschlossen war
296 				//	(GrabFocus passiert in KillEditView)
297 			}
298 			break;
299 
300 		case SID_OPENDLG_FUNCTION:
301 			{
302 				sal_uInt16 nId = SID_OPENDLG_FUNCTION;
303 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
304 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
305 
306 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
307                 rReq.Ignore();
308 			}
309 			break;
310 
311 		case SID_OPENDLG_CONSOLIDATE:
312 			{
313 				sal_uInt16			nId  = ScConsolidateDlgWrapper::GetChildWindowId();
314 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
315 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
316 
317 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
318 			}
319 			break;
320 
321 		case FID_CELL_FORMAT:
322 			{
323 				if ( pReqArgs != NULL )
324 				{
325 					//----------------------------------
326 					// Zellattribute ohne Dialog setzen:
327 					//----------------------------------
328 					SfxItemSet* 	pEmptySet =
329 										new SfxItemSet( *pReqArgs->GetPool(),
330 														ATTR_PATTERN_START,
331 														ATTR_PATTERN_END );
332 
333 					SfxItemSet* 	pNewSet =
334 										new SfxItemSet( *pReqArgs->GetPool(),
335 														ATTR_PATTERN_START,
336 														ATTR_PATTERN_END );
337 
338 					const SfxPoolItem*	pAttr = NULL;
339 					sal_uInt16				nWhich = 0;
340 
341 					for ( nWhich=ATTR_PATTERN_START; nWhich<=ATTR_PATTERN_END; nWhich++ )
342 						if ( pReqArgs->GetItemState( nWhich, sal_True, &pAttr ) == SFX_ITEM_SET )
343 							pNewSet->Put( *pAttr );
344 
345 					pTabViewShell->ApplyAttributes( pNewSet, pEmptySet );
346 
347 					delete pNewSet;
348 					delete pEmptySet;
349 
350 					rReq.Done();
351 				}
352 				else if ( pReqArgs == NULL )
353 				{
354 					pTabViewShell->ExecuteCellFormatDlg( rReq );
355 				}
356 			}
357 			break;
358 
359 		case SID_ENABLE_HYPHENATION:
360 			pTabViewShell->ExecuteCellFormatDlg( rReq, TP_ALIGNMENT );
361 			break;
362 
363 		case SID_CHAR_DLG_EFFECT:
364 			pTabViewShell->ExecuteCellFormatDlg( rReq, TP_FONTEFF );
365 			break;
366 
367 		case SID_OPENDLG_SOLVE:
368 			{
369 				sal_uInt16			nId  = ScSolverDlgWrapper::GetChildWindowId();
370 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
371 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
372 
373 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
374 			}
375 			break;
376 
377         case SID_OPENDLG_OPTSOLVER:
378             {
379                 sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
380                 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
381                 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
382 
383                 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
384             }
385             break;
386 
387 		case SID_OPENDLG_TABOP:
388 			{
389 				sal_uInt16			nId  = ScTabOpDlgWrapper::GetChildWindowId();
390 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
391 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
392 
393 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
394 			}
395 			break;
396 
397 		case SID_SCENARIOS:
398 			{
399 				ScDocument* pDoc = GetViewData()->GetDocument();
400 				ScMarkData& rMark = GetViewData()->GetMarkData();
401 				SCTAB nTab = GetViewData()->GetTabNo();
402 
403 				if ( pDoc->IsScenario(nTab) )
404 				{
405 					rMark.MarkToMulti();
406 					if ( rMark.IsMultiMarked() )
407 					{
408 						if (   rReq.IsAPI()
409 							|| RET_YES ==
410 							   QueryBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
411 										 ScGlobal::GetRscString(STR_UPDATE_SCENARIO) ).
412 										Execute() )
413 						{
414 							pTabViewShell->ExtendScenario();
415 							rReq.Done();
416 						}
417 					}
418 					else if( ! rReq.IsAPI() )
419 					{
420 						ErrorBox aErrorBox( pTabViewShell->GetDialogParent(), WinBits(WB_OK | WB_DEF_OK),
421 											ScGlobal::GetRscString(STR_NOAREASELECTED) );
422 						aErrorBox.Execute();
423 					}
424 				}
425 				else
426 				{
427 					rMark.MarkToMulti();
428 					if ( rMark.IsMultiMarked() )
429 					{
430 						SCTAB i=1;
431 						String aBaseName;
432 						String aName;
433 						String aComment;
434 						Color  aColor;
435 						sal_uInt16 nFlags;
436 
437 						pDoc->GetName( nTab, aBaseName );
438 						aBaseName += '_';
439 						aBaseName += ScGlobal::GetRscString(STR_SCENARIO);
440 						aBaseName += '_';
441 
442 						//	vorneweg testen, ob der Prefix als gueltig erkannt wird
443 						//	wenn nicht, nur doppelte vermeiden
444 						sal_Bool bPrefix = pDoc->ValidTabName( aBaseName );
445 						DBG_ASSERT(bPrefix, "ungueltiger Tabellenname");
446 
447 						while ( pDoc->IsScenario(nTab+i) )
448 							i++;
449 
450 						sal_Bool bValid;
451 						SCTAB nDummy;
452 						do
453 						{
454 							aName = aBaseName;
455 							aName += String::CreateFromInt32( i );
456 							if (bPrefix)
457 								bValid = pDoc->ValidNewTabName( aName );
458 							else
459 								bValid = !pDoc->GetTable( aName, nDummy );
460 							++i;
461 						}
462 						while ( !bValid && i <= 2*MAXTAB );
463 
464 						if ( pReqArgs != NULL )
465 						{
466 							String aArgName;
467 							String aArgComment;
468 							const SfxPoolItem* pItem;
469 							if ( pReqArgs->GetItemState( SID_SCENARIOS, sal_True, &pItem ) == SFX_ITEM_SET )
470 								aArgName = ((const SfxStringItem*)pItem)->GetValue();
471 							if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, sal_True, &pItem ) == SFX_ITEM_SET )
472 								aArgComment = ((const SfxStringItem*)pItem)->GetValue();
473 
474 							aColor = Color( COL_LIGHTGRAY );		// Default
475 							nFlags = 0;								// nicht-TwoWay
476 
477 							pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
478 							if( ! rReq.IsAPI() )
479 								rReq.Done();
480 						}
481 						else
482 						{
483 							sal_Bool bSheetProtected = pDoc->IsTabProtected(nTab);
484 							//CHINA001 ScNewScenarioDlg* pNewDlg =
485 							//CHINA001 	new ScNewScenarioDlg( pTabViewShell->GetDialogParent(), aName, sal_False, bSheetProtected );
486 							ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
487 							DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
488 
489 							AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( pTabViewShell->GetDialogParent(), aName, RID_SCDLG_NEWSCENARIO, sal_False,bSheetProtected);
490 							DBG_ASSERT(pNewDlg, "Dialog create fail!");//CHINA001
491 							if ( pNewDlg->Execute() == RET_OK )
492 							{
493 								pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
494 								pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
495 
496 								rReq.AppendItem( SfxStringItem( SID_SCENARIOS, aName ) );
497 								rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
498 								rReq.Done();
499 							}
500 							delete pNewDlg;
501 						}
502 					}
503 					else if( ! rReq.IsAPI() )
504 					{
505 						pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
506 					}
507 				}
508 			}
509 			break;
510 
511 
512 		case SID_SELECTALL:
513 			{
514 				pTabViewShell->SelectAll();
515 				rReq.Done();
516 			}
517 			break;
518 
519 		//----------------------------------------------------------------
520 
521 		case FID_ROW_HEIGHT:
522 			{
523 				if ( pReqArgs )
524 				{
525 					const SfxUInt16Item&  rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_HEIGHT );
526 
527                     // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
528                     pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_DIRECT,
529                                     sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
530 					if( ! rReq.IsAPI() )
531 						rReq.Done();
532 				}
533 				else
534 				{
535 					ScViewData* pData      = GetViewData();
536 					FieldUnit	eMetric    = SC_MOD()->GetAppOptions().GetAppMetric();
537 					sal_uInt16		nCurHeight = pData->GetDocument()->
538 												GetRowHeight( pData->GetCurY(),
539 															  pData->GetTabNo() );
540 //CHINA001					ScMetricInputDlg* pDlg =
541 //CHINA001					new ScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_MAN,
542 //CHINA001					nCurHeight,
543 //CHINA001					ScGlobal::nStdRowHeight,
544 //CHINA001					eMetric,
545 //CHINA001					2,
546 //CHINA001					MAX_COL_HEIGHT );
547 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
548 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
549 
550 					AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_MAN,
551 																					nCurHeight,
552 																					ScGlobal::nStdRowHeight,
553 																					RID_SCDLG_ROW_MAN,
554 																					eMetric,
555 																					2,
556 																					MAX_COL_HEIGHT);
557 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
558 
559 					if ( pDlg->Execute() == RET_OK )
560 					{
561 						long nVal = pDlg->GetInputValue();
562 						pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_DIRECT, (sal_uInt16)nVal );
563 
564                         // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
565 						rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
566 						rReq.Done();
567 
568 					}
569 					delete pDlg;
570 				}
571 			}
572 			break;
573 
574 		case FID_ROW_OPT_HEIGHT:
575 			{
576 				if ( pReqArgs )
577 				{
578 					const SfxUInt16Item&  rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_OPT_HEIGHT );
579 
580                     // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
581                     pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_OPTIMAL,
582                                     sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
583 					ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
584 
585 					if( ! rReq.IsAPI() )
586 						rReq.Done();
587 				}
588 				else
589 				{
590 					FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
591 
592 //CHINA001					ScMetricInputDlg* pDlg =
593 //CHINA001					new ScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_OPT,
594 //CHINA001					ScGlobal::nLastRowHeightExtra,
595 //CHINA001					0,
596 //CHINA001					eMetric,
597 //CHINA001					1,
598 //CHINA001					MAX_EXTRA_HEIGHT );
599 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
600 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
601 
602 					AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_OPT,
603 																					ScGlobal::nLastRowHeightExtra,
604 																					0,
605 																					RID_SCDLG_ROW_OPT,
606 																					eMetric,
607 																					1,
608 																					MAX_EXTRA_HEIGHT);
609 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
610 
611 					if ( pDlg->Execute() == RET_OK )
612 					{
613 						long nVal = pDlg->GetInputValue();
614 						pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
615 						ScGlobal::nLastRowHeightExtra = nVal;
616 
617                         // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
618 						rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
619 						rReq.Done();
620 
621 					}
622 					delete pDlg;
623 				}
624 			}
625 			break;
626 
627 		case FID_COL_WIDTH:
628 			{
629 				if ( pReqArgs )
630 				{
631 					const SfxUInt16Item&  rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_WIDTH );
632 
633                     // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
634                     pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT,
635                                     sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
636 					if( ! rReq.IsAPI() )
637 						rReq.Done();
638 				}
639 				else
640 				{
641 					FieldUnit   eMetric	   = SC_MOD()->GetAppOptions().GetAppMetric();
642 					ScViewData* pData      = GetViewData();
643 					sal_uInt16		nCurHeight = pData->GetDocument()->
644 												GetColWidth( pData->GetCurX(),
645 															 pData->GetTabNo() );
646 //CHINA001					ScMetricInputDlg* pDlg =
647 //CHINA001					new ScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_MAN,
648 //CHINA001					nCurHeight,
649 //CHINA001					STD_COL_WIDTH,
650 //CHINA001					eMetric,
651 //CHINA001					2,
652 //CHINA001					MAX_COL_WIDTH );
653 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
654 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
655 
656 					AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_MAN,
657 																					nCurHeight,
658 																					STD_COL_WIDTH,
659 																					RID_SCDLG_COL_MAN,
660 																					eMetric,
661 																					2,
662 																					MAX_COL_WIDTH);
663 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
664 
665 					if ( pDlg->Execute() == RET_OK )
666 					{
667 						long nVal = pDlg->GetInputValue();
668 						pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, (sal_uInt16)nVal );
669 
670                         // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
671 						rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
672 						rReq.Done();
673 
674 					}
675 					delete pDlg;
676 				}
677 			}
678 			break;
679 
680 		case FID_COL_OPT_WIDTH:
681 			{
682 				if ( pReqArgs )
683 				{
684 					const SfxUInt16Item&  rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_OPT_WIDTH );
685 
686                     // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
687                     pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL,
688                                     sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
689 					ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
690 
691 					if( ! rReq.IsAPI() )
692 						rReq.Done();
693 				}
694 				else
695 				{
696 					FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
697 
698 //CHINA001					ScMetricInputDlg* pDlg =
699 //CHINA001					new ScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_OPT,
700 //CHINA001					ScGlobal::nLastColWidthExtra,
701 //CHINA001					STD_EXTRA_WIDTH,
702 //CHINA001					eMetric,
703 //CHINA001					1,
704 //CHINA001					MAX_EXTRA_WIDTH );
705 
706 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
707 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
708 
709 					AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_OPT,
710 																					ScGlobal::nLastColWidthExtra,
711 																					STD_EXTRA_WIDTH,
712 																					RID_SCDLG_COL_OPT,
713 																					eMetric,
714 																					1,
715 																					MAX_EXTRA_WIDTH);
716 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
717 					if ( pDlg->Execute() == RET_OK )
718 					{
719 						long nVal = pDlg->GetInputValue();
720 						pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
721 						ScGlobal::nLastColWidthExtra = nVal;
722 
723                         // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
724 						rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
725 						rReq.Done();
726 					}
727 					delete pDlg;
728 				}
729 			}
730 			break;
731 
732 		case FID_COL_OPT_DIRECT:
733 			pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
734 			rReq.Done();
735 			break;
736 
737 		case FID_ROW_HIDE:
738 			pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_DIRECT, 0 );
739 			rReq.Done();
740 			break;
741 		case FID_ROW_SHOW:
742 			pTabViewShell->SetMarkedWidthOrHeight( sal_False, SC_SIZE_SHOW, 0 );
743 			rReq.Done();
744 			break;
745 		case FID_COL_HIDE:
746 			pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, 0 );
747 			rReq.Done();
748 			break;
749 		case FID_COL_SHOW:
750 			pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_SHOW, 0 );
751 			rReq.Done();
752 			break;
753 
754 		//----------------------------------------------------------------
755 
756 
757 		case SID_CELL_FORMAT_RESET:
758 			{
759 				pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
760 				rReq.Done();
761 			}
762 			break;
763 
764 		case FID_MERGE_ON:
765         case FID_MERGE_OFF:
766         case FID_MERGE_TOGGLE:
767         {
768             if ( !GetViewData()->GetDocument()->GetChangeTrack() )
769             {
770                 // test whether to merge or to split
771                 bool bMerge = false;
772                 switch( nSlot )
773                 {
774                     case FID_MERGE_ON:
775                         bMerge = true;
776                     break;
777                     case FID_MERGE_OFF:
778                         bMerge = false;
779                     break;
780                     case FID_MERGE_TOGGLE:
781                     {
782                         SfxPoolItem* pItem = 0;
783                         if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
784                             bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
785                     }
786                     break;
787                 }
788 
789                 if( bMerge )
790                 {
791                     // merge - check if to move contents of covered cells
792                     sal_Bool bMoveContents = sal_False;
793                     sal_Bool bApi = rReq.IsAPI();
794                     const SfxPoolItem* pItem;
795                     if ( pReqArgs &&
796                         pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
797                     {
798                         DBG_ASSERT(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
799                         bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
800                     }
801 
802                     if (pTabViewShell->MergeCells( bApi, bMoveContents ))
803                     {
804                         if (!bApi && bMoveContents)             // "ja" im Dialog geklickt
805                             rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
806                         rBindings.Invalidate( nSlot );
807                         rReq.Done();
808                     }
809                 }
810                 else
811                 {
812                     // split cells
813                     if (pTabViewShell->RemoveMerge())
814                     {
815                         rBindings.Invalidate( nSlot );
816                         rReq.Done();
817                     }
818                 }
819                 break;
820             }
821         }
822         break;
823 
824 		case SID_AUTOFORMAT:
825 			{
826 				Window* pDlgParent = pTabViewShell->GetDialogParent();
827 				SCCOL nStartCol;
828 				SCROW nStartRow;
829 				SCTAB nStartTab;
830 				SCCOL nEndCol;
831 				SCROW nEndRow;
832 				SCTAB nEndTab;
833 
834 				const ScMarkData& rMark = GetViewData()->GetMarkData();
835 				if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
836 					pTabViewShell->MarkDataArea( sal_True );
837 
838 				GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
839 											  nEndCol,nEndRow,nEndTab );
840 
841 				if (   ( Abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
842 					&& ( Abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
843 				{
844 					if ( pReqArgs )
845 					{
846 						const SfxStringItem& rNameItem = (const SfxStringItem&)pReqArgs->Get( SID_AUTOFORMAT );
847 						ScAutoFormat* pFormat = ScGlobal::GetAutoFormat();
848 						sal_uInt16 nIndex = pFormat->FindIndexPerName( rNameItem.GetValue() );
849 
850 						pTabViewShell->AutoFormat( nIndex );
851 
852 						if( ! rReq.IsAPI() )
853 							rReq.Done();
854 					}
855 					else
856 					{
857 						ScGlobal::ClearAutoFormat();
858 						ScAutoFormatData* pNewEntry = pTabViewShell->CreateAutoFormatData();
859 //CHINA001						ScAutoFormatDlg*  pDlg		= new ScAutoFormatDlg(
860 //CHINA001						pDlgParent,
861 //CHINA001						ScGlobal::GetAutoFormat(),
862 //CHINA001						pNewEntry,
863 //CHINA001						GetViewData()->GetDocument() );
864 						ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
865 						DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
866 
867 						AbstractScAutoFormatDlg* pDlg = pFact->CreateScAutoFormatDlg( pDlgParent, ScGlobal::GetAutoFormat(), pNewEntry,GetViewData()->GetDocument(), RID_SCDLG_AUTOFORMAT );
868 						DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
869 
870 						if ( pDlg->Execute() == RET_OK )
871 						{
872 							ScEditableTester aTester( pTabViewShell );
873 							if ( !aTester.IsEditable() )
874 							{
875 								pTabViewShell->ErrorMessage(aTester.GetMessageId());
876 							}
877 							else
878 							{
879 								pTabViewShell->AutoFormat( pDlg->GetIndex() );
880 
881 								rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
882 								rReq.Done();
883 							}
884 						}
885 						delete pDlg;
886 						delete pNewEntry;
887 					}
888 				}
889 				else
890 					ErrorBox( pDlgParent, WinBits( WB_OK | WB_DEF_OK ),
891 							  ScGlobal::GetRscString(STR_INVALID_AFAREA) ).Execute();
892 			}
893 			break;
894 
895 		case SID_CANCEL:
896 			{
897 				if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
898 					pScMod->InputCancelHandler();
899                 else if (pTabViewShell->HasPaintBrush())
900                     pTabViewShell->ResetBrushDocument();            // abort format paint brush
901 				else if (pTabViewShell->HasHintWindow())
902 					pTabViewShell->RemoveHintWindow();				// Eingabemeldung abschalten
903                 else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
904                     ScViewUtil::SetFullScreen( *pTabViewShell, false );
905 				else
906 				{
907                     // TODO/LATER: when is this code executed?
908                     pTabViewShell->Escape();
909                     //SfxObjectShell* pObjSh = GetViewData()->GetSfxDocShell();
910                     //if (pObjSh->GetInPlaceObject() &&
911                     //    pObjSh->GetInPlaceObject()->GetIPClient())
912                     //{
913                     //    GetViewData()->GetDocShell()->
914                     //        DoInPlaceActivate(sal_False);       // OLE beenden
915                     //}
916 				}
917 
918 //				SetSumAssignMode(); //ScInputWindow
919 			}
920 			break;
921 
922 		case SID_DATA_SELECT:
923 			pTabViewShell->StartDataSelect();
924 			break;
925 
926 		case SID_DETECTIVE_FILLMODE:
927 			{
928 				sal_Bool bOldMode = pTabViewShell->IsAuditShell();
929 				pTabViewShell->SetAuditShell( !bOldMode );
930 				pTabViewShell->Invalidate( nSlot );
931 			}
932 			break;
933 
934 		case SID_OPENDLG_CONDFRMT:
935 			{
936 				sal_uInt16			nId  = ScCondFormatDlgWrapper::GetChildWindowId();
937 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
938 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
939 
940 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
941 			}
942 			break;
943 
944 		//	----------------------------------------------------------------
945 
946 		case FID_INPUTLINE_STATUS:
947 			DBG_ERROR("Execute von InputLine-Status");
948 			break;
949 
950         case SID_STATUS_DOCPOS:
951             // Launch navigator.
952             GetViewData()->GetDispatcher().Execute(
953                 SID_NAVIGATOR, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
954             break;
955 
956 		case SID_MARKAREA:
957 			// called from Basic at the hidden view to select a range in the visible view
958 			DBG_ERROR("old slot SID_MARKAREA");
959 			break;
960 
961 		default:
962 			DBG_ERROR("Unbekannter Slot bei ScCellShell::Execute");
963 			break;
964 	}
965 }
966 
967