Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / cellsh3.cxx
blob3ab047f6384b7f7b2bad7d143f4470a91fa8d47b
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 #include <boost/scoped_ptr.hpp>
53 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
55 using sc::HMMToTwips;
56 using sc::TwipsToHMM;
57 using sc::TwipsToEvenHMM;
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(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 )
326 // set cell attribute without dialog:
328 boost::scoped_ptr<SfxItemSet> pEmptySet(
329 new SfxItemSet( *pReqArgs->GetPool(),
330 ATTR_PATTERN_START,
331 ATTR_PATTERN_END ));
333 boost::scoped_ptr<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, true, &pAttr ) == SFX_ITEM_SET )
343 pNewSet->Put( *pAttr );
345 pTabViewShell->ApplyAttributes( pNewSet.get(), pEmptySet.get() );
347 pNewSet.reset();
348 pEmptySet.reset();
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 bool bPrefix = pDoc->ValidTabName( aBaseName );
455 OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
457 while ( pDoc->IsScenario(nTab+i) )
458 i++;
460 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, true, &pItem ) == SFX_ITEM_SET )
479 aArgName = ((const SfxStringItem*)pItem)->GetValue();
480 if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, 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 bool bSheetProtected = pDoc->IsTabProtected(nTab);
493 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
494 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
496 boost::scoped_ptr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(pTabViewShell->GetDialogParent(), aName, 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();
509 else if( ! rReq.IsAPI() )
511 pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
515 break;
518 case SID_SELECTALL:
520 pTabViewShell->SelectAll();
521 rReq.Done();
523 break;
525 case FID_ROW_HEIGHT:
527 if ( pReqArgs )
529 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_HEIGHT );
531 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
532 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
533 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
534 if( ! rReq.IsAPI() )
535 rReq.Done();
537 else
539 ScViewData* pData = GetViewData();
540 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
541 sal_uInt16 nCurHeight = pData->GetDocument()->
542 GetRowHeight( pData->GetCurY(),
543 pData->GetTabNo() );
544 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
545 assert(pFact); //ScAbstractFactory create fail!
547 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
548 pTabViewShell->GetDialogParent(), "RowHeightDialog",
549 nCurHeight, ScGlobal::nStdRowHeight,
550 eMetric, 2, MAX_ROW_HEIGHT));
551 assert(pDlg); //Dialog create fail
553 if ( pDlg->Execute() == RET_OK )
555 long nVal = pDlg->GetInputValue();
556 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, (sal_uInt16)nVal );
558 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
559 rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
560 rReq.Done();
565 break;
567 case FID_ROW_OPT_HEIGHT:
569 if ( pReqArgs )
571 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_OPT_HEIGHT );
573 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
574 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
575 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
576 ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
578 if( ! rReq.IsAPI() )
579 rReq.Done();
581 else
583 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
585 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
586 assert(pFact); //ScAbstractFactory create fail!
588 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
589 pTabViewShell->GetDialogParent(), "OptimalRowHeightDialog",
590 ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT));
591 assert(pDlg); //Dialog create fail!
593 if ( pDlg->Execute() == RET_OK )
595 long nVal = pDlg->GetInputValue();
596 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
597 ScGlobal::nLastRowHeightExtra = nVal;
599 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
600 rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
601 rReq.Done();
606 break;
608 case FID_COL_WIDTH:
610 if ( pReqArgs )
612 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_WIDTH );
614 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
615 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT,
616 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
617 if( ! rReq.IsAPI() )
618 rReq.Done();
620 else
622 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
623 ScViewData* pData = GetViewData();
624 sal_uInt16 nCurHeight = pData->GetDocument()->
625 GetColWidth( pData->GetCurX(),
626 pData->GetTabNo() );
627 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
628 assert(pFact); //ScAbstractFactory create fail!
630 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
631 pTabViewShell->GetDialogParent(), "ColWidthDialog", nCurHeight,
632 STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH));
633 assert(pDlg); //Dialog create fail!
635 if ( pDlg->Execute() == RET_OK )
637 long nVal = pDlg->GetInputValue();
638 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, (sal_uInt16)nVal );
640 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
641 rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
642 rReq.Done();
647 break;
649 case FID_COL_OPT_WIDTH:
651 if ( pReqArgs )
653 const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_OPT_WIDTH );
655 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
656 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL,
657 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
658 ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
660 if( ! rReq.IsAPI() )
661 rReq.Done();
663 else
665 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
667 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
668 assert(pFact); //ScAbstractFactory create fail!
670 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
671 pTabViewShell->GetDialogParent(), "OptimalColWidthDialog",
672 ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH));
673 assert(pDlg); //Dialog create fail!
674 if ( pDlg->Execute() == RET_OK )
676 long nVal = pDlg->GetInputValue();
677 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
678 ScGlobal::nLastColWidthExtra = nVal;
680 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
681 rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
682 rReq.Done();
686 break;
688 case FID_COL_OPT_DIRECT:
689 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
690 rReq.Done();
691 break;
693 case FID_ROW_HIDE:
694 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
695 rReq.Done();
696 break;
697 case FID_ROW_SHOW:
698 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
699 rReq.Done();
700 break;
701 case FID_COL_HIDE:
702 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, 0 );
703 rReq.Done();
704 break;
705 case FID_COL_SHOW:
706 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_SHOW, 0 );
707 rReq.Done();
708 break;
711 case SID_CELL_FORMAT_RESET:
713 pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
714 rReq.Done();
716 break;
718 case FID_MERGE_ON:
719 case FID_MERGE_OFF:
720 case FID_MERGE_TOGGLE:
722 if ( !GetViewData()->GetDocument()->GetChangeTrack() )
724 // test whether to merge or to split
725 bool bMerge = false;
726 bool bCenter = false;
727 switch( nSlot )
729 case FID_MERGE_ON:
730 bMerge = true;
731 break;
732 case FID_MERGE_OFF:
733 bMerge = false;
734 break;
735 case FID_MERGE_TOGGLE:
737 bCenter = true;
738 SfxPoolItem* pItem = 0;
739 if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
740 bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
742 delete pItem;
744 break;
747 if( bMerge )
749 // merge - check if to move contents of covered cells
750 bool bMoveContents = false;
751 bool bApi = rReq.IsAPI();
752 const SfxPoolItem* pItem;
753 if ( pReqArgs &&
754 pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
756 OSL_ENSURE(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
757 bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
760 if (pTabViewShell->MergeCells( bApi, bMoveContents, true, bCenter ))
762 if (!bApi && bMoveContents) // "yes" clicked in dialog
763 rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
764 rBindings.Invalidate( nSlot );
765 rReq.Done();
768 else
770 // split cells
771 if (pTabViewShell->RemoveMerge())
773 rBindings.Invalidate( nSlot );
774 rReq.Done();
777 break;
780 break;
782 case SID_AUTOFORMAT:
784 Window* pDlgParent = pTabViewShell->GetDialogParent();
785 SCCOL nStartCol;
786 SCROW nStartRow;
787 SCTAB nStartTab;
788 SCCOL nEndCol;
789 SCROW nEndRow;
790 SCTAB nEndTab;
792 const ScMarkData& rMark = GetViewData()->GetMarkData();
793 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
794 pTabViewShell->MarkDataArea( true );
796 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
797 nEndCol,nEndRow,nEndTab );
799 if ( ( std::abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
800 && ( std::abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
802 if ( pReqArgs )
804 const SfxStringItem& rNameItem = (const SfxStringItem&)pReqArgs->Get( SID_AUTOFORMAT );
805 ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
806 ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
807 ScAutoFormat::const_iterator itBeg = pFormat->begin();
808 size_t nIndex = std::distance(itBeg, it);
810 pTabViewShell->AutoFormat( nIndex );
812 if( ! rReq.IsAPI() )
813 rReq.Done();
815 else
817 ScGlobal::ClearAutoFormat();
818 boost::scoped_ptr<ScAutoFormatData> pNewEntry(pTabViewShell->CreateAutoFormatData());
819 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
820 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
822 boost::scoped_ptr<AbstractScAutoFormatDlg> pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData()));
823 OSL_ENSURE(pDlg, "Dialog create fail!");
825 if ( pDlg->Execute() == RET_OK )
827 ScEditableTester aTester( pTabViewShell );
828 if ( !aTester.IsEditable() )
830 pTabViewShell->ErrorMessage(aTester.GetMessageId());
832 else
834 pTabViewShell->AutoFormat( pDlg->GetIndex() );
836 rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
837 rReq.Done();
842 else
843 ErrorBox( pDlgParent, WinBits( WB_OK | WB_DEF_OK ),
844 ScGlobal::GetRscString(STR_INVALID_AFAREA) ).Execute();
846 break;
848 case SID_CANCEL:
850 if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
851 pScMod->InputCancelHandler();
852 else if (pTabViewShell->HasPaintBrush())
853 pTabViewShell->ResetBrushDocument(); // abort format paint brush
854 else if (pTabViewShell->HasHintWindow())
855 pTabViewShell->RemoveHintWindow();
856 else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
857 ScViewUtil::SetFullScreen( *pTabViewShell, false );
858 else
860 // TODO/LATER: when is this code executed?
861 pTabViewShell->Escape();
864 break;
866 case SID_DATA_SELECT:
867 pTabViewShell->StartDataSelect();
868 break;
870 case SID_DETECTIVE_FILLMODE:
872 bool bOldMode = pTabViewShell->IsAuditShell();
873 pTabViewShell->SetAuditShell( !bOldMode );
874 pTabViewShell->Invalidate( nSlot );
876 break;
878 case FID_INPUTLINE_STATUS:
879 OSL_FAIL("Execute von InputLine-Status");
880 break;
882 case SID_STATUS_DOCPOS:
883 // Launch navigator.
884 GetViewData()->GetDispatcher().Execute(
885 SID_NAVIGATOR, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
886 break;
888 case SID_MARKAREA:
889 // called from Basic at the hidden view to select a range in the visible view
890 OSL_FAIL("old slot SID_MARKAREA");
891 break;
893 default:
894 OSL_FAIL("Unbekannter Slot bei ScCellShell::Execute");
895 break;
899 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */