GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / view / cellsh3.cxx
blob3720e003810bdc4617ed51d64f17845050b9cf5c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
21 #include <sfx2/viewfrm.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/request.hxx>
25 #include <svl/stritem.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <sfx2/app.hxx>
28 #include "globstr.hrc"
29 #include "scmod.hxx"
30 #include "appoptio.hxx"
31 #include "tabvwsh.hxx"
32 #include "document.hxx"
33 #include "sc.hrc"
34 #include "docsh.hxx"
35 #include "reffact.hxx"
36 #include "uiitems.hxx"
37 #include "autoform.hxx"
38 #include "autofmt.hxx"
39 #include "cellsh.hxx"
40 #include "inputhdl.hxx"
41 #include "editable.hxx"
42 #include "markdata.hxx"
43 #include "scabstdlg.hxx"
45 #include <config_telepathy.h>
47 #if ENABLE_TELEPATHY
48 #include "sccollaboration.hxx"
49 #endif
51 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
53 using sc::HMMToTwips;
54 using sc::TwipsToHMM;
55 using sc::TwipsToEvenHMM;
57 //------------------------------------------------------------------
59 void ScCellShell::Execute( SfxRequest& rReq )
61 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
62 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
63 ScModule* pScMod = SC_MOD();
64 const SfxItemSet* pReqArgs = rReq.GetArgs();
65 sal_uInt16 nSlot = rReq.GetSlot();
67 if (nSlot != SID_CURRENTCELL) // this comes with MouseButtonUp
68 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
70 if ( IS_EDITMODE() )
72 switch ( nSlot )
74 // when opening a reference-dialog the subshell may not be switched
75 // (on closing the dialog StopEditShell is called)
76 case SID_OPENDLG_FUNCTION:
77 // inplace leads to trouble with EditShell ...
78 //! cannot always be switched werden ????
79 if (!pTabViewShell->GetViewFrame()->GetFrame().IsInPlace())
80 pTabViewShell->SetDontSwitch(sal_True); // do not switch off EditShell
81 // no break
83 case FID_CELL_FORMAT:
84 case SID_ENABLE_HYPHENATION:
85 case SID_DATA_SELECT:
86 case SID_OPENDLG_CONSOLIDATE:
87 case SID_OPENDLG_SOLVE:
88 case SID_OPENDLG_OPTSOLVER:
90 pScMod->InputEnterHandler();
91 pTabViewShell->UpdateInputHandler();
93 pTabViewShell->SetDontSwitch(false);
95 break;
97 default:
98 break;
102 switch ( nSlot )
104 case SID_ATTR_SIZE://XXX ???
105 break;
107 case SID_COLLABORATION:
108 #if ENABLE_TELEPATHY
109 GetViewData()->GetDocShell()->GetCollaboration()->DisplayContacts();
110 #endif
111 break;
113 case SID_STATUS_SELMODE:
114 if ( pReqArgs )
116 /* 0: STD Click cancels selection
117 * 1: ER Click extends selection
118 * 2: ERG Click defines further selection
120 sal_uInt16 nMode = ((const SfxUInt16Item&)pReqArgs->Get( nSlot )).GetValue();
122 switch ( nMode )
124 case 1: nMode = KEY_SHIFT; break;
125 case 2: nMode = KEY_MOD1; break; // control-key
126 case 0:
127 default:
128 nMode = 0;
131 pTabViewShell->LockModifiers( nMode );
133 else
135 // no arguments (also executed by double click on the status bar controller):
136 // advance to next selection mode
138 sal_uInt16 nModifiers = pTabViewShell->GetLockedModifiers();
139 switch ( nModifiers )
141 case KEY_SHIFT: nModifiers = KEY_MOD1; break; // EXT -> ADD
142 case KEY_MOD1: nModifiers = 0; break; // ADD -> STD
143 default: nModifiers = KEY_SHIFT; break; // STD -> EXT
145 pTabViewShell->LockModifiers( nModifiers );
148 rBindings.Invalidate( SID_STATUS_SELMODE );
149 rReq.Done();
150 break;
152 // SID_STATUS_SELMODE_NORM is not used ???
154 case SID_STATUS_SELMODE_NORM:
155 pTabViewShell->LockModifiers( 0 );
156 rBindings.Invalidate( SID_STATUS_SELMODE );
157 break;
159 // SID_STATUS_SELMODE_ERG / SID_STATUS_SELMODE_ERW as toggles:
161 case SID_STATUS_SELMODE_ERG:
162 if ( pTabViewShell->GetLockedModifiers() & KEY_MOD1 )
163 pTabViewShell->LockModifiers( 0 );
164 else
165 pTabViewShell->LockModifiers( KEY_MOD1 );
166 rBindings.Invalidate( SID_STATUS_SELMODE );
167 break;
169 case SID_STATUS_SELMODE_ERW:
170 if ( pTabViewShell->GetLockedModifiers() & KEY_SHIFT )
171 pTabViewShell->LockModifiers( 0 );
172 else
173 pTabViewShell->LockModifiers( KEY_SHIFT );
174 rBindings.Invalidate( SID_STATUS_SELMODE );
175 break;
177 case SID_ENTER_STRING:
179 if ( pReqArgs )
181 OUString aStr( ((const SfxStringItem&)pReqArgs->
182 Get( SID_ENTER_STRING )).GetValue() );
184 pTabViewShell->EnterData( GetViewData()->GetCurX(),
185 GetViewData()->GetCurY(),
186 GetViewData()->GetTabNo(),
187 aStr );
189 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
190 if ( !pHdl || !pHdl->IsInEnterHandler() )
192 // UpdateInputHandler is needed after the cell content
193 // has changed, but if called from EnterHandler, UpdateInputHandler
194 // will be called later when moving the cursor.
196 pTabViewShell->UpdateInputHandler();
199 rReq.Done();
201 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
202 // sideview, when the input was not finished
203 // (GrabFocus is called in KillEditView)
206 break;
208 case SID_INSERT_MATRIX:
210 if ( pReqArgs )
212 OUString aStr = ((const SfxStringItem&)pReqArgs->
213 Get( SID_INSERT_MATRIX )).GetValue();
214 ScDocument* pDoc = GetViewData()->GetDocument();
215 pTabViewShell->EnterMatrix( aStr, pDoc->GetGrammar() );
216 rReq.Done();
219 break;
221 case FID_INPUTLINE_ENTER:
222 case FID_INPUTLINE_BLOCK:
223 case FID_INPUTLINE_MATRIX:
225 if( pReqArgs == 0 ) //XXX temporary HACK to avoid GPF
226 break;
228 const ScInputStatusItem* pStatusItem
229 = (const ScInputStatusItem*)&pReqArgs->
230 Get( FID_INPUTLINE_STATUS );
232 ScAddress aCursorPos = pStatusItem->GetPos();
233 OUString aString = pStatusItem->GetString();
234 const EditTextObject* pData = pStatusItem->GetEditData();
236 if (pData)
238 if (nSlot == FID_INPUTLINE_BLOCK)
240 pTabViewShell->EnterBlock( aString, pData );
242 else if ( !aString.isEmpty() && ( aString[0] == '=' || aString[0] == '+' || aString[0] == '-' ) )
244 pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, pData );
246 else
248 pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
251 else
253 if (nSlot == FID_INPUTLINE_ENTER)
255 if (
256 aCursorPos.Col() == GetViewData()->GetCurX() &&
257 aCursorPos.Row() == GetViewData()->GetCurY() &&
258 aCursorPos.Tab() == GetViewData()->GetTabNo()
261 SfxStringItem aItem( SID_ENTER_STRING, aString );
263 // SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
264 const SfxPoolItem* aArgs[2];
265 aArgs[0] = &aItem;
266 aArgs[1] = NULL;
267 rBindings.Execute( SID_ENTER_STRING, aArgs );
269 else
271 pTabViewShell->EnterData( aCursorPos.Col(),
272 aCursorPos.Row(),
273 aCursorPos.Tab(),
274 aString );
275 rReq.Done();
278 else if (nSlot == FID_INPUTLINE_BLOCK)
280 pTabViewShell->EnterBlock( aString, NULL );
281 rReq.Done();
283 else
285 ScDocument* pDoc = GetViewData()->GetDocument();
286 pTabViewShell->EnterMatrix( aString, pDoc->GetGrammar() );
287 rReq.Done();
291 pTabViewShell->SetAutoSpellData(
292 aCursorPos.Col(), aCursorPos.Row(), pStatusItem->GetMisspellRanges());
294 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
295 // sideview, when the input was not finished
296 // (GrabFocus is called in KillEditView)
298 break;
300 case SID_OPENDLG_FUNCTION:
302 sal_uInt16 nId = SID_OPENDLG_FUNCTION;
303 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
304 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
306 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
307 rReq.Ignore();
309 break;
311 case SID_OPENDLG_CONSOLIDATE:
313 sal_uInt16 nId = ScConsolidateDlgWrapper::GetChildWindowId();
314 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
315 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
317 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
319 break;
321 case FID_CELL_FORMAT:
323 if ( pReqArgs != NULL )
325 //----------------------------------
326 // set cell attribute without dialog:
327 //----------------------------------
328 SfxItemSet* pEmptySet =
329 new SfxItemSet( *pReqArgs->GetPool(),
330 ATTR_PATTERN_START,
331 ATTR_PATTERN_END );
333 SfxItemSet* pNewSet =
334 new SfxItemSet( *pReqArgs->GetPool(),
335 ATTR_PATTERN_START,
336 ATTR_PATTERN_END );
338 const SfxPoolItem* pAttr = NULL;
339 sal_uInt16 nWhich = 0;
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 );
345 pTabViewShell->ApplyAttributes( pNewSet, pEmptySet );
347 delete pNewSet;
348 delete pEmptySet;
350 rReq.Done();
352 else if ( pReqArgs == NULL )
354 pTabViewShell->ExecuteCellFormatDlg( rReq );
357 break;
359 case SID_ENABLE_HYPHENATION:
360 pTabViewShell->ExecuteCellFormatDlg(rReq, "alignment");
361 break;
363 case SID_PROPERTY_PANEL_CELLTEXT_DLG:
364 pTabViewShell->ExecuteCellFormatDlg( rReq, "font" );
365 break;
367 case SID_CELL_FORMAT_BORDER:
368 pTabViewShell->ExecuteCellFormatDlg( rReq, "borders" );
369 break;
371 case SID_CHAR_DLG_EFFECT:
372 pTabViewShell->ExecuteCellFormatDlg( rReq, "fonteffects" );
373 break;
375 case SID_OPENDLG_SOLVE:
377 sal_uInt16 nId = ScSolverDlgWrapper::GetChildWindowId();
378 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
379 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
381 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
383 break;
385 case SID_OPENDLG_OPTSOLVER:
387 sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
388 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
389 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
391 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
393 break;
395 case SID_OPENDLG_TABOP:
397 sal_uInt16 nId = ScTabOpDlgWrapper::GetChildWindowId();
398 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
399 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
401 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
403 break;
405 case SID_SCENARIOS:
407 ScDocument* pDoc = GetViewData()->GetDocument();
408 ScMarkData& rMark = GetViewData()->GetMarkData();
409 SCTAB nTab = GetViewData()->GetTabNo();
411 if ( pDoc->IsScenario(nTab) )
413 rMark.MarkToMulti();
414 if ( rMark.IsMultiMarked() )
416 if ( rReq.IsAPI()
417 || RET_YES ==
418 QueryBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
419 ScGlobal::GetRscString(STR_UPDATE_SCENARIO) ).
420 Execute() )
422 pTabViewShell->ExtendScenario();
423 rReq.Done();
426 else if( ! rReq.IsAPI() )
428 ErrorBox aErrorBox( pTabViewShell->GetDialogParent(), WinBits(WB_OK | WB_DEF_OK),
429 ScGlobal::GetRscString(STR_NOAREASELECTED) );
430 aErrorBox.Execute();
433 else
435 rMark.MarkToMulti();
436 if ( rMark.IsMultiMarked() )
438 SCTAB i=1;
439 OUString aBaseName;
440 OUString aName;
441 OUString aComment;
442 Color aColor;
443 sal_uInt16 nFlags;
445 OUString aTmp;
446 pDoc->GetName(nTab, aTmp);
447 aBaseName = aTmp;
448 aBaseName += "_";
449 aBaseName += ScGlobal::GetRscString(STR_SCENARIO);
450 aBaseName += "_";
452 // first test, if the prefix is recognised as valid,
453 // else avoid only doubles
454 sal_Bool bPrefix = pDoc->ValidTabName( aBaseName );
455 OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
457 while ( pDoc->IsScenario(nTab+i) )
458 i++;
460 sal_Bool bValid;
461 SCTAB nDummy;
464 aName = aBaseName + OUString::number( i );
465 if (bPrefix)
466 bValid = pDoc->ValidNewTabName( aName );
467 else
468 bValid = !pDoc->GetTable( aName, nDummy );
469 ++i;
471 while ( !bValid && i <= MAXTAB + 2 );
473 if ( pReqArgs != NULL )
475 OUString aArgName;
476 OUString aArgComment;
477 const SfxPoolItem* pItem;
478 if ( pReqArgs->GetItemState( SID_SCENARIOS, sal_True, &pItem ) == SFX_ITEM_SET )
479 aArgName = ((const SfxStringItem*)pItem)->GetValue();
480 if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, sal_True, &pItem ) == SFX_ITEM_SET )
481 aArgComment = ((const SfxStringItem*)pItem)->GetValue();
483 aColor = Color( COL_LIGHTGRAY ); // Default
484 nFlags = 0; // not-TwoWay
486 pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
487 if( ! rReq.IsAPI() )
488 rReq.Done();
490 else
492 sal_Bool bSheetProtected = pDoc->IsTabProtected(nTab);
493 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
494 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
496 AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( pTabViewShell->GetDialogParent(), aName, RID_SCDLG_NEWSCENARIO, false,bSheetProtected);
497 OSL_ENSURE(pNewDlg, "Dialog create fail!");
498 if ( pNewDlg->Execute() == RET_OK )
500 pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
501 pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
503 rReq.AppendItem( SfxStringItem( SID_SCENARIOS, aName ) );
504 rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
505 rReq.Done();
507 delete pNewDlg;
510 else if( ! rReq.IsAPI() )
512 pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
516 break;
519 case SID_SELECTALL:
521 pTabViewShell->SelectAll();
522 rReq.Done();
524 break;
526 //----------------------------------------------------------------
528 case FID_ROW_HEIGHT:
530 if ( pReqArgs )
532 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_HEIGHT );
534 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
535 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
536 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
537 if( ! rReq.IsAPI() )
538 rReq.Done();
540 else
542 ScViewData* pData = GetViewData();
543 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
544 sal_uInt16 nCurHeight = pData->GetDocument()->
545 GetRowHeight( pData->GetCurY(),
546 pData->GetTabNo() );
547 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
548 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
550 AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_MAN,
551 nCurHeight,
552 ScGlobal::nStdRowHeight,
553 RID_SCDLG_ROW_MAN,
554 eMetric,
556 MAX_ROW_HEIGHT);
557 OSL_ENSURE(pDlg, "Dialog create fail!");
559 if ( pDlg->Execute() == RET_OK )
561 long nVal = pDlg->GetInputValue();
562 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, (sal_uInt16)nVal );
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();
569 delete pDlg;
572 break;
574 case FID_ROW_OPT_HEIGHT:
576 if ( pReqArgs )
578 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_OPT_HEIGHT );
580 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
581 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
582 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
583 ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
585 if( ! rReq.IsAPI() )
586 rReq.Done();
588 else
590 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
592 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
593 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
595 AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_OPT,
596 ScGlobal::nLastRowHeightExtra,
598 RID_SCDLG_ROW_OPT,
599 eMetric,
601 MAX_EXTRA_HEIGHT);
602 OSL_ENSURE(pDlg, "Dialog create fail!");
604 if ( pDlg->Execute() == RET_OK )
606 long nVal = pDlg->GetInputValue();
607 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
608 ScGlobal::nLastRowHeightExtra = nVal;
610 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
611 rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
612 rReq.Done();
615 delete pDlg;
618 break;
620 case FID_COL_WIDTH:
622 if ( pReqArgs )
624 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_WIDTH );
626 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
627 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT,
628 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
629 if( ! rReq.IsAPI() )
630 rReq.Done();
632 else
634 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
635 ScViewData* pData = GetViewData();
636 sal_uInt16 nCurHeight = pData->GetDocument()->
637 GetColWidth( pData->GetCurX(),
638 pData->GetTabNo() );
639 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
640 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
642 AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_MAN,
643 nCurHeight,
644 STD_COL_WIDTH,
645 RID_SCDLG_COL_MAN,
646 eMetric,
648 MAX_COL_WIDTH);
649 OSL_ENSURE(pDlg, "Dialog create fail!");
651 if ( pDlg->Execute() == RET_OK )
653 long nVal = pDlg->GetInputValue();
654 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, (sal_uInt16)nVal );
656 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
657 rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
658 rReq.Done();
661 delete pDlg;
664 break;
666 case FID_COL_OPT_WIDTH:
668 if ( pReqArgs )
670 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_OPT_WIDTH );
672 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
673 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL,
674 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
675 ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
677 if( ! rReq.IsAPI() )
678 rReq.Done();
680 else
682 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
684 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
685 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
687 AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_OPT,
688 ScGlobal::nLastColWidthExtra,
689 STD_EXTRA_WIDTH,
690 RID_SCDLG_COL_OPT,
691 eMetric,
693 MAX_EXTRA_WIDTH);
694 OSL_ENSURE(pDlg, "Dialog create fail!");
695 if ( pDlg->Execute() == RET_OK )
697 long nVal = pDlg->GetInputValue();
698 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
699 ScGlobal::nLastColWidthExtra = nVal;
701 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
702 rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
703 rReq.Done();
705 delete pDlg;
708 break;
710 case FID_COL_OPT_DIRECT:
711 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
712 rReq.Done();
713 break;
715 case FID_ROW_HIDE:
716 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
717 rReq.Done();
718 break;
719 case FID_ROW_SHOW:
720 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
721 rReq.Done();
722 break;
723 case FID_COL_HIDE:
724 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, 0 );
725 rReq.Done();
726 break;
727 case FID_COL_SHOW:
728 pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_SHOW, 0 );
729 rReq.Done();
730 break;
732 //----------------------------------------------------------------
735 case SID_CELL_FORMAT_RESET:
737 pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
738 rReq.Done();
740 break;
742 case FID_MERGE_ON:
743 case FID_MERGE_OFF:
744 case FID_MERGE_TOGGLE:
746 if ( !GetViewData()->GetDocument()->GetChangeTrack() )
748 // test whether to merge or to split
749 bool bMerge = false;
750 sal_Bool bCenter = false;
751 switch( nSlot )
753 case FID_MERGE_ON:
754 bMerge = true;
755 break;
756 case FID_MERGE_OFF:
757 bMerge = false;
758 break;
759 case FID_MERGE_TOGGLE:
761 bCenter = true;
762 SfxPoolItem* pItem = 0;
763 if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
764 bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
766 delete pItem;
768 break;
771 if( bMerge )
773 // merge - check if to move contents of covered cells
774 sal_Bool bMoveContents = false;
775 sal_Bool bApi = rReq.IsAPI();
776 const SfxPoolItem* pItem;
777 if ( pReqArgs &&
778 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
780 OSL_ENSURE(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
781 bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
784 if (pTabViewShell->MergeCells( bApi, bMoveContents, true, bCenter ))
786 if (!bApi && bMoveContents) // "yes" clicked in dialog
787 rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
788 rBindings.Invalidate( nSlot );
789 rReq.Done();
792 else
794 // split cells
795 if (pTabViewShell->RemoveMerge())
797 rBindings.Invalidate( nSlot );
798 rReq.Done();
801 break;
804 break;
806 case SID_AUTOFORMAT:
808 Window* pDlgParent = pTabViewShell->GetDialogParent();
809 SCCOL nStartCol;
810 SCROW nStartRow;
811 SCTAB nStartTab;
812 SCCOL nEndCol;
813 SCROW nEndRow;
814 SCTAB nEndTab;
816 const ScMarkData& rMark = GetViewData()->GetMarkData();
817 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
818 pTabViewShell->MarkDataArea( sal_True );
820 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
821 nEndCol,nEndRow,nEndTab );
823 if ( ( std::abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
824 && ( std::abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
826 if ( pReqArgs )
828 const SfxStringItem& rNameItem = (const SfxStringItem&)pReqArgs->Get( SID_AUTOFORMAT );
829 ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
830 ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
831 ScAutoFormat::const_iterator itBeg = pFormat->begin();
832 size_t nIndex = std::distance(itBeg, it);
834 pTabViewShell->AutoFormat( nIndex );
836 if( ! rReq.IsAPI() )
837 rReq.Done();
839 else
841 ScGlobal::ClearAutoFormat();
842 ScAutoFormatData* pNewEntry = pTabViewShell->CreateAutoFormatData();
843 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
844 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
846 AbstractScAutoFormatDlg* pDlg = pFact->CreateScAutoFormatDlg( pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry,GetViewData()->GetDocument(), RID_SCDLG_AUTOFORMAT );
847 OSL_ENSURE(pDlg, "Dialog create fail!");
849 if ( pDlg->Execute() == RET_OK )
851 ScEditableTester aTester( pTabViewShell );
852 if ( !aTester.IsEditable() )
854 pTabViewShell->ErrorMessage(aTester.GetMessageId());
856 else
858 pTabViewShell->AutoFormat( pDlg->GetIndex() );
860 rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
861 rReq.Done();
864 delete pDlg;
865 delete pNewEntry;
868 else
869 ErrorBox( pDlgParent, WinBits( WB_OK | WB_DEF_OK ),
870 ScGlobal::GetRscString(STR_INVALID_AFAREA) ).Execute();
872 break;
874 case SID_CANCEL:
876 if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
877 pScMod->InputCancelHandler();
878 else if (pTabViewShell->HasPaintBrush())
879 pTabViewShell->ResetBrushDocument(); // abort format paint brush
880 else if (pTabViewShell->HasHintWindow())
881 pTabViewShell->RemoveHintWindow();
882 else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
883 ScViewUtil::SetFullScreen( *pTabViewShell, false );
884 else
886 // TODO/LATER: when is this code executed?
887 pTabViewShell->Escape();
890 break;
892 case SID_DATA_SELECT:
893 pTabViewShell->StartDataSelect();
894 break;
896 case SID_DETECTIVE_FILLMODE:
898 sal_Bool bOldMode = pTabViewShell->IsAuditShell();
899 pTabViewShell->SetAuditShell( !bOldMode );
900 pTabViewShell->Invalidate( nSlot );
902 break;
904 // ----------------------------------------------------------------
906 case FID_INPUTLINE_STATUS:
907 OSL_FAIL("Execute von InputLine-Status");
908 break;
910 case SID_STATUS_DOCPOS:
911 // Launch navigator.
912 GetViewData()->GetDispatcher().Execute(
913 SID_NAVIGATOR, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
914 break;
916 case SID_MARKAREA:
917 // called from Basic at the hidden view to select a range in the visible view
918 OSL_FAIL("old slot SID_MARKAREA");
919 break;
921 default:
922 OSL_FAIL("Unbekannter Slot bei ScCellShell::Execute");
923 break;
927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */