fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / cellsh3.cxx
blobb1b5d7f6a8ed015e44ee37cd1aecbec52a3beea9
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_COLLABORATION:
105 #if ENABLE_TELEPATHY
106 GetViewData()->GetDocShell()->GetCollaboration()->DisplayContacts();
107 #endif
108 break;
110 case SID_STATUS_SELMODE:
111 if ( pReqArgs )
113 /* 0: STD Click cancels selection
114 * 1: ER Click extends selection
115 * 2: ERG Click defines further selection
117 sal_uInt16 nMode = static_cast<const SfxUInt16Item&>(pReqArgs->Get( nSlot )).GetValue();
119 switch ( nMode )
121 case 1: nMode = KEY_SHIFT; break;
122 case 2: nMode = KEY_MOD1; break; // control-key
123 case 0:
124 default:
125 nMode = 0;
128 pTabViewShell->LockModifiers( nMode );
130 else
132 // no arguments (also executed by double click on the status bar controller):
133 // advance to next selection mode
135 sal_uInt16 nModifiers = pTabViewShell->GetLockedModifiers();
136 switch ( nModifiers )
138 case KEY_SHIFT: nModifiers = KEY_MOD1; break; // EXT -> ADD
139 case KEY_MOD1: nModifiers = 0; break; // ADD -> STD
140 default: nModifiers = KEY_SHIFT; break; // STD -> EXT
142 pTabViewShell->LockModifiers( nModifiers );
145 rBindings.Invalidate( SID_STATUS_SELMODE );
146 rReq.Done();
147 break;
149 // SID_STATUS_SELMODE_NORM is not used ???
151 case SID_STATUS_SELMODE_NORM:
152 pTabViewShell->LockModifiers( 0 );
153 rBindings.Invalidate( SID_STATUS_SELMODE );
154 break;
156 // SID_STATUS_SELMODE_ERG / SID_STATUS_SELMODE_ERW as toggles:
158 case SID_STATUS_SELMODE_ERG:
159 if ( pTabViewShell->GetLockedModifiers() & KEY_MOD1 )
160 pTabViewShell->LockModifiers( 0 );
161 else
162 pTabViewShell->LockModifiers( KEY_MOD1 );
163 rBindings.Invalidate( SID_STATUS_SELMODE );
164 break;
166 case SID_STATUS_SELMODE_ERW:
167 if ( pTabViewShell->GetLockedModifiers() & KEY_SHIFT )
168 pTabViewShell->LockModifiers( 0 );
169 else
170 pTabViewShell->LockModifiers( KEY_SHIFT );
171 rBindings.Invalidate( SID_STATUS_SELMODE );
172 break;
174 case SID_ENTER_STRING:
176 if ( pReqArgs )
178 OUString aStr( static_cast<const SfxStringItem&>(pReqArgs->
179 Get( SID_ENTER_STRING )).GetValue() );
181 pTabViewShell->EnterData( GetViewData()->GetCurX(),
182 GetViewData()->GetCurY(),
183 GetViewData()->GetTabNo(),
184 aStr );
186 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
187 if ( !pHdl || !pHdl->IsInEnterHandler() )
189 // UpdateInputHandler is needed after the cell content
190 // has changed, but if called from EnterHandler, UpdateInputHandler
191 // will be called later when moving the cursor.
193 pTabViewShell->UpdateInputHandler();
196 rReq.Done();
198 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
199 // sideview, when the input was not finished
200 // (GrabFocus is called in KillEditView)
203 break;
205 case SID_INSERT_MATRIX:
207 if ( pReqArgs )
209 OUString aStr = static_cast<const SfxStringItem&>(pReqArgs->
210 Get( SID_INSERT_MATRIX )).GetValue();
211 ScDocument* pDoc = GetViewData()->GetDocument();
212 pTabViewShell->EnterMatrix( aStr, pDoc->GetGrammar() );
213 rReq.Done();
216 break;
218 case FID_INPUTLINE_ENTER:
219 case FID_INPUTLINE_BLOCK:
220 case FID_INPUTLINE_MATRIX:
222 if( pReqArgs == 0 ) //XXX temporary HACK to avoid GPF
223 break;
225 const ScInputStatusItem* pStatusItem
226 = static_cast<const ScInputStatusItem*>(&pReqArgs->
227 Get( FID_INPUTLINE_STATUS ));
229 ScAddress aCursorPos = pStatusItem->GetPos();
230 OUString aString = pStatusItem->GetString();
231 const EditTextObject* pData = pStatusItem->GetEditData();
233 if (pData)
235 if (nSlot == FID_INPUTLINE_BLOCK)
237 pTabViewShell->EnterBlock( aString, pData );
239 else if ( !aString.isEmpty() && ( aString[0] == '=' || aString[0] == '+' || aString[0] == '-' ) )
241 pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, pData );
243 else
245 pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
248 else
250 if (nSlot == FID_INPUTLINE_ENTER)
252 if (
253 aCursorPos.Col() == GetViewData()->GetCurX() &&
254 aCursorPos.Row() == GetViewData()->GetCurY() &&
255 aCursorPos.Tab() == GetViewData()->GetTabNo()
258 SfxStringItem aItem( SID_ENTER_STRING, aString );
260 // SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
261 const SfxPoolItem* aArgs[2];
262 aArgs[0] = &aItem;
263 aArgs[1] = NULL;
264 rBindings.Execute( SID_ENTER_STRING, aArgs );
266 else
268 pTabViewShell->EnterData( aCursorPos.Col(),
269 aCursorPos.Row(),
270 aCursorPos.Tab(),
271 aString );
272 rReq.Done();
275 else if (nSlot == FID_INPUTLINE_BLOCK)
277 pTabViewShell->EnterBlock( aString, NULL );
278 rReq.Done();
280 else
282 ScDocument* pDoc = GetViewData()->GetDocument();
283 pTabViewShell->EnterMatrix( aString, pDoc->GetGrammar() );
284 rReq.Done();
288 pTabViewShell->SetAutoSpellData(
289 aCursorPos.Col(), aCursorPos.Row(), pStatusItem->GetMisspellRanges());
291 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
292 // sideview, when the input was not finished
293 // (GrabFocus is called in KillEditView)
295 break;
297 case SID_OPENDLG_FUNCTION:
299 sal_uInt16 nId = SID_OPENDLG_FUNCTION;
300 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
301 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
303 pScMod->SetRefDialog( nId, pWnd == nullptr );
304 rReq.Ignore();
306 break;
308 case SID_OPENDLG_CONSOLIDATE:
310 sal_uInt16 nId = ScConsolidateDlgWrapper::GetChildWindowId();
311 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
312 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
314 pScMod->SetRefDialog( nId, pWnd == nullptr );
316 break;
318 case FID_CELL_FORMAT:
320 if ( pReqArgs != NULL )
323 // set cell attribute without dialog:
325 boost::scoped_ptr<SfxItemSet> pEmptySet(
326 new SfxItemSet( *pReqArgs->GetPool(),
327 ATTR_PATTERN_START,
328 ATTR_PATTERN_END ));
330 boost::scoped_ptr<SfxItemSet> pNewSet(
331 new SfxItemSet( *pReqArgs->GetPool(),
332 ATTR_PATTERN_START,
333 ATTR_PATTERN_END ));
335 const SfxPoolItem* pAttr = NULL;
336 sal_uInt16 nWhich = 0;
338 for ( nWhich=ATTR_PATTERN_START; nWhich<=ATTR_PATTERN_END; nWhich++ )
339 if ( pReqArgs->GetItemState( nWhich, true, &pAttr ) == SfxItemState::SET )
340 pNewSet->Put( *pAttr );
342 pTabViewShell->ApplyAttributes( pNewSet.get(), pEmptySet.get() );
344 pNewSet.reset();
345 pEmptySet.reset();
347 rReq.Done();
349 else if ( pReqArgs == NULL )
351 pTabViewShell->ExecuteCellFormatDlg( rReq );
354 break;
356 case SID_ENABLE_HYPHENATION:
357 pTabViewShell->ExecuteCellFormatDlg(rReq, "alignment");
358 break;
360 case SID_PROPERTY_PANEL_CELLTEXT_DLG:
361 pTabViewShell->ExecuteCellFormatDlg( rReq, "font" );
362 break;
364 case SID_CELL_FORMAT_BORDER:
365 pTabViewShell->ExecuteCellFormatDlg( rReq, "borders" );
366 break;
368 case SID_CHAR_DLG_EFFECT:
369 pTabViewShell->ExecuteCellFormatDlg( rReq, "fonteffects" );
370 break;
372 case SID_OPENDLG_SOLVE:
374 sal_uInt16 nId = ScSolverDlgWrapper::GetChildWindowId();
375 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
376 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
378 pScMod->SetRefDialog( nId, pWnd == nullptr );
380 break;
382 case SID_OPENDLG_OPTSOLVER:
384 sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
385 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
386 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
388 pScMod->SetRefDialog( nId, pWnd == nullptr );
390 break;
392 case SID_OPENDLG_TABOP:
394 sal_uInt16 nId = ScTabOpDlgWrapper::GetChildWindowId();
395 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
396 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
398 pScMod->SetRefDialog( nId, pWnd == nullptr );
400 break;
402 case SID_SCENARIOS:
404 ScDocument* pDoc = GetViewData()->GetDocument();
405 ScMarkData& rMark = GetViewData()->GetMarkData();
406 SCTAB nTab = GetViewData()->GetTabNo();
408 if ( pDoc->IsScenario(nTab) )
410 rMark.MarkToMulti();
411 if ( rMark.IsMultiMarked() )
413 if ( rReq.IsAPI()
414 || RET_YES ==
415 ScopedVclPtr<QueryBox>::Create( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
416 ScGlobal::GetRscString(STR_UPDATE_SCENARIO) )->
417 Execute() )
419 pTabViewShell->ExtendScenario();
420 rReq.Done();
423 else if( ! rReq.IsAPI() )
425 ScopedVclPtrInstance<MessageDialog> aErrorBox(pTabViewShell->GetDialogParent(),
426 ScGlobal::GetRscString(STR_NOAREASELECTED));
427 aErrorBox->Execute();
430 else
432 rMark.MarkToMulti();
433 if ( rMark.IsMultiMarked() )
435 SCTAB i=1;
436 OUString aBaseName;
437 OUString aName;
438 OUString aComment;
439 Color aColor;
440 sal_uInt16 nFlags;
442 OUString aTmp;
443 pDoc->GetName(nTab, aTmp);
444 aBaseName = aTmp;
445 aBaseName += "_";
446 aBaseName += ScGlobal::GetRscString(STR_SCENARIO);
447 aBaseName += "_";
449 // first test, if the prefix is recognised as valid,
450 // else avoid only doubles
451 bool bPrefix = ScDocument::ValidTabName( aBaseName );
452 OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
454 while ( pDoc->IsScenario(nTab+i) )
455 i++;
457 bool bValid;
458 SCTAB nDummy;
461 aName = aBaseName + OUString::number( i );
462 if (bPrefix)
463 bValid = pDoc->ValidNewTabName( aName );
464 else
465 bValid = !pDoc->GetTable( aName, nDummy );
466 ++i;
468 while ( !bValid && i <= MAXTAB + 2 );
470 if ( pReqArgs != NULL )
472 OUString aArgName;
473 OUString aArgComment;
474 const SfxPoolItem* pItem;
475 if ( pReqArgs->GetItemState( SID_SCENARIOS, true, &pItem ) == SfxItemState::SET )
476 aArgName = static_cast<const SfxStringItem*>(pItem)->GetValue();
477 if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, true, &pItem ) == SfxItemState::SET )
478 aArgComment = static_cast<const SfxStringItem*>(pItem)->GetValue();
480 aColor = Color( COL_LIGHTGRAY ); // Default
481 nFlags = 0; // not-TwoWay
483 pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
484 if( ! rReq.IsAPI() )
485 rReq.Done();
487 else
489 bool bSheetProtected = pDoc->IsTabProtected(nTab);
490 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
491 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
493 boost::scoped_ptr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(pTabViewShell->GetDialogParent(), aName, false, bSheetProtected));
494 OSL_ENSURE(pNewDlg, "Dialog create fail!");
495 if ( pNewDlg->Execute() == RET_OK )
497 pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
498 pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
500 rReq.AppendItem( SfxStringItem( SID_SCENARIOS, aName ) );
501 rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
502 rReq.Done();
506 else if( ! rReq.IsAPI() )
508 pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
512 break;
514 case SID_SELECTALL:
516 pTabViewShell->SelectAll();
517 rReq.Done();
519 break;
521 case FID_ROW_HEIGHT:
523 if ( pReqArgs )
525 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_HEIGHT ));
527 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
528 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
529 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
530 if( ! rReq.IsAPI() )
531 rReq.Done();
533 else
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 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
541 assert(pFact); //ScAbstractFactory create fail!
543 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
544 pTabViewShell->GetDialogParent(), "RowHeightDialog",
545 nCurHeight, ScGlobal::nStdRowHeight,
546 eMetric, 2, MAX_ROW_HEIGHT));
547 assert(pDlg); //Dialog create fail
549 if ( pDlg->Execute() == RET_OK )
551 long nVal = pDlg->GetInputValue();
552 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, (sal_uInt16)nVal );
554 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
555 rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
556 rReq.Done();
561 break;
563 case FID_ROW_OPT_HEIGHT:
565 if ( pReqArgs )
567 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_OPT_HEIGHT ));
569 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
570 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
571 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
572 ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
574 if( ! rReq.IsAPI() )
575 rReq.Done();
577 else
579 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
581 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
582 assert(pFact); //ScAbstractFactory create fail!
584 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
585 pTabViewShell->GetDialogParent(), "OptimalRowHeightDialog",
586 ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT));
587 assert(pDlg); //Dialog create fail!
589 if ( pDlg->Execute() == RET_OK )
591 long nVal = pDlg->GetInputValue();
592 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
593 ScGlobal::nLastRowHeightExtra = nVal;
595 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
596 rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
597 rReq.Done();
602 break;
604 case FID_COL_WIDTH:
606 if ( pReqArgs )
608 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_WIDTH ));
610 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
611 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT,
612 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
613 if( ! rReq.IsAPI() )
614 rReq.Done();
616 else
618 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
619 ScViewData* pData = GetViewData();
620 sal_uInt16 nCurHeight = pData->GetDocument()->
621 GetColWidth( pData->GetCurX(),
622 pData->GetTabNo() );
623 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
624 assert(pFact); //ScAbstractFactory create fail!
626 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
627 pTabViewShell->GetDialogParent(), "ColWidthDialog", nCurHeight,
628 STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH));
629 assert(pDlg); //Dialog create fail!
631 if ( pDlg->Execute() == RET_OK )
633 long nVal = pDlg->GetInputValue();
634 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, (sal_uInt16)nVal );
636 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
637 rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
638 rReq.Done();
643 break;
645 case FID_COL_OPT_WIDTH:
647 if ( pReqArgs )
649 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_OPT_WIDTH ));
651 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
652 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL,
653 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
654 ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
656 if( ! rReq.IsAPI() )
657 rReq.Done();
659 else
661 FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
663 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
664 assert(pFact); //ScAbstractFactory create fail!
666 boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
667 pTabViewShell->GetDialogParent(), "OptimalColWidthDialog",
668 ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH));
669 assert(pDlg); //Dialog create fail!
670 if ( pDlg->Execute() == RET_OK )
672 long nVal = pDlg->GetInputValue();
673 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
674 ScGlobal::nLastColWidthExtra = nVal;
676 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
677 rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
678 rReq.Done();
682 break;
684 case FID_COL_OPT_DIRECT:
685 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
686 rReq.Done();
687 break;
689 case FID_ROW_HIDE:
690 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
691 rReq.Done();
692 break;
693 case FID_ROW_SHOW:
694 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
695 rReq.Done();
696 break;
697 case FID_COL_HIDE:
698 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, 0 );
699 rReq.Done();
700 break;
701 case FID_COL_SHOW:
702 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_SHOW, 0 );
703 rReq.Done();
704 break;
706 case SID_CELL_FORMAT_RESET:
708 pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
709 rReq.Done();
711 break;
713 case FID_MERGE_ON:
714 case FID_MERGE_OFF:
715 case FID_MERGE_TOGGLE:
717 if ( !GetViewData()->GetDocument()->GetChangeTrack() )
719 // test whether to merge or to split
720 bool bMerge = false;
721 bool bCenter = false;
722 switch( nSlot )
724 case FID_MERGE_ON:
725 bMerge = true;
726 break;
727 case FID_MERGE_OFF:
728 bMerge = false;
729 break;
730 case FID_MERGE_TOGGLE:
732 bCenter = true;
733 SfxPoolItem* pItem = 0;
734 if( rBindings.QueryState( nSlot, pItem ) >= SfxItemState::DEFAULT )
735 bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
737 delete pItem;
739 break;
742 if( bMerge )
744 // merge - check if to move contents of covered cells
745 bool bMoveContents = false;
746 bool bApi = rReq.IsAPI();
747 const SfxPoolItem* pItem;
748 if ( pReqArgs &&
749 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
751 OSL_ENSURE(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
752 bMoveContents = static_cast<const SfxBoolItem*>(pItem)->GetValue();
755 if (pTabViewShell->MergeCells( bApi, bMoveContents, true, bCenter ))
757 if (!bApi && bMoveContents) // "yes" clicked in dialog
758 rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
759 rBindings.Invalidate( nSlot );
760 rReq.Done();
763 else
765 // split cells
766 if (pTabViewShell->RemoveMerge())
768 rBindings.Invalidate( nSlot );
769 rReq.Done();
772 break;
775 break;
777 case SID_AUTOFORMAT:
779 vcl::Window* pDlgParent = pTabViewShell->GetDialogParent();
780 SCCOL nStartCol;
781 SCROW nStartRow;
782 SCTAB nStartTab;
783 SCCOL nEndCol;
784 SCROW nEndRow;
785 SCTAB nEndTab;
787 const ScMarkData& rMark = GetViewData()->GetMarkData();
788 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
789 pTabViewShell->MarkDataArea( true );
791 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
792 nEndCol,nEndRow,nEndTab );
794 if ( ( std::abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
795 && ( std::abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
797 if ( pReqArgs )
799 const SfxStringItem& rNameItem = static_cast<const SfxStringItem&>(pReqArgs->Get( SID_AUTOFORMAT ));
800 ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
801 ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
802 ScAutoFormat::const_iterator itBeg = pFormat->begin();
803 size_t nIndex = std::distance(itBeg, it);
805 pTabViewShell->AutoFormat( nIndex );
807 if( ! rReq.IsAPI() )
808 rReq.Done();
810 else
812 ScGlobal::ClearAutoFormat();
813 boost::scoped_ptr<ScAutoFormatData> pNewEntry(pTabViewShell->CreateAutoFormatData());
814 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
815 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
817 boost::scoped_ptr<AbstractScAutoFormatDlg> pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData()));
818 OSL_ENSURE(pDlg, "Dialog create fail!");
820 if ( pDlg->Execute() == RET_OK )
822 ScEditableTester aTester( pTabViewShell );
823 if ( !aTester.IsEditable() )
825 pTabViewShell->ErrorMessage(aTester.GetMessageId());
827 else
829 pTabViewShell->AutoFormat( pDlg->GetIndex() );
831 rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
832 rReq.Done();
837 else
838 ScopedVclPtrInstance<MessageDialog>(pDlgParent,
839 ScGlobal::GetRscString(STR_INVALID_AFAREA) )->Execute();
841 break;
843 case SID_CANCEL:
845 if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
846 pScMod->InputCancelHandler();
847 else if (pTabViewShell->HasPaintBrush())
848 pTabViewShell->ResetBrushDocument(); // abort format paint brush
849 else if (pTabViewShell->HasHintWindow())
850 pTabViewShell->RemoveHintWindow();
851 else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
852 ScViewUtil::SetFullScreen( *pTabViewShell, false );
853 else
855 // TODO/LATER: when is this code executed?
856 pTabViewShell->Escape();
859 break;
861 case SID_DATA_SELECT:
862 pTabViewShell->StartDataSelect();
863 break;
865 case SID_DETECTIVE_FILLMODE:
867 bool bOldMode = pTabViewShell->IsAuditShell();
868 pTabViewShell->SetAuditShell( !bOldMode );
869 pTabViewShell->Invalidate( nSlot );
871 break;
873 case FID_INPUTLINE_STATUS:
874 OSL_FAIL("Execute von InputLine-Status");
875 break;
877 case SID_STATUS_DOCPOS:
878 // Launch navigator.
879 GetViewData()->GetDispatcher().Execute(
880 SID_NAVIGATOR, SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
881 break;
883 case SID_MARKAREA:
884 // called from Basic at the hidden view to select a range in the visible view
885 OSL_FAIL("old slot SID_MARKAREA");
886 break;
888 default:
889 OSL_FAIL("Unbekannter Slot bei ScCellShell::Execute");
890 break;
894 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */