Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
44 :
45 : #include <config_telepathy.h>
46 :
47 : #if ENABLE_TELEPATHY
48 : #include "sccollaboration.hxx"
49 : #endif
50 :
51 : #include <boost/scoped_ptr.hpp>
52 :
53 : #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
54 :
55 : using sc::HMMToTwips;
56 : using sc::TwipsToHMM;
57 : using sc::TwipsToEvenHMM;
58 :
59 0 : void ScCellShell::Execute( SfxRequest& rReq )
60 : {
61 0 : ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
62 0 : SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
63 0 : ScModule* pScMod = SC_MOD();
64 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
65 0 : sal_uInt16 nSlot = rReq.GetSlot();
66 :
67 0 : if (nSlot != SID_CURRENTCELL) // this comes with MouseButtonUp
68 0 : pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
69 :
70 0 : if ( IS_EDITMODE() )
71 : {
72 0 : switch ( nSlot )
73 : {
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 0 : if (!pTabViewShell->GetViewFrame()->GetFrame().IsInPlace())
80 0 : pTabViewShell->SetDontSwitch(true); // do not switch off EditShell
81 : // no break
82 :
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:
89 :
90 0 : pScMod->InputEnterHandler();
91 0 : pTabViewShell->UpdateInputHandler();
92 :
93 0 : pTabViewShell->SetDontSwitch(false);
94 :
95 0 : break;
96 :
97 : default:
98 0 : break;
99 : }
100 : }
101 :
102 0 : switch ( nSlot )
103 : {
104 : case SID_ATTR_SIZE://XXX ???
105 0 : break;
106 :
107 : case SID_COLLABORATION:
108 : #if ENABLE_TELEPATHY
109 : GetViewData()->GetDocShell()->GetCollaboration()->DisplayContacts();
110 : #endif
111 0 : break;
112 :
113 : case SID_STATUS_SELMODE:
114 0 : if ( pReqArgs )
115 : {
116 : /* 0: STD Click cancels selection
117 : * 1: ER Click extends selection
118 : * 2: ERG Click defines further selection
119 : */
120 0 : sal_uInt16 nMode = static_cast<const SfxUInt16Item&>(pReqArgs->Get( nSlot )).GetValue();
121 :
122 0 : switch ( nMode )
123 : {
124 0 : case 1: nMode = KEY_SHIFT; break;
125 0 : case 2: nMode = KEY_MOD1; break; // control-key
126 : case 0:
127 : default:
128 0 : nMode = 0;
129 : }
130 :
131 0 : pTabViewShell->LockModifiers( nMode );
132 : }
133 : else
134 : {
135 : // no arguments (also executed by double click on the status bar controller):
136 : // advance to next selection mode
137 :
138 0 : sal_uInt16 nModifiers = pTabViewShell->GetLockedModifiers();
139 0 : switch ( nModifiers )
140 : {
141 0 : case KEY_SHIFT: nModifiers = KEY_MOD1; break; // EXT -> ADD
142 0 : case KEY_MOD1: nModifiers = 0; break; // ADD -> STD
143 0 : default: nModifiers = KEY_SHIFT; break; // STD -> EXT
144 : }
145 0 : pTabViewShell->LockModifiers( nModifiers );
146 : }
147 :
148 0 : rBindings.Invalidate( SID_STATUS_SELMODE );
149 0 : rReq.Done();
150 0 : break;
151 :
152 : // SID_STATUS_SELMODE_NORM is not used ???
153 :
154 : case SID_STATUS_SELMODE_NORM:
155 0 : pTabViewShell->LockModifiers( 0 );
156 0 : rBindings.Invalidate( SID_STATUS_SELMODE );
157 0 : break;
158 :
159 : // SID_STATUS_SELMODE_ERG / SID_STATUS_SELMODE_ERW as toggles:
160 :
161 : case SID_STATUS_SELMODE_ERG:
162 0 : if ( pTabViewShell->GetLockedModifiers() & KEY_MOD1 )
163 0 : pTabViewShell->LockModifiers( 0 );
164 : else
165 0 : pTabViewShell->LockModifiers( KEY_MOD1 );
166 0 : rBindings.Invalidate( SID_STATUS_SELMODE );
167 0 : break;
168 :
169 : case SID_STATUS_SELMODE_ERW:
170 0 : if ( pTabViewShell->GetLockedModifiers() & KEY_SHIFT )
171 0 : pTabViewShell->LockModifiers( 0 );
172 : else
173 0 : pTabViewShell->LockModifiers( KEY_SHIFT );
174 0 : rBindings.Invalidate( SID_STATUS_SELMODE );
175 0 : break;
176 :
177 : case SID_ENTER_STRING:
178 : {
179 0 : if ( pReqArgs )
180 : {
181 : OUString aStr( static_cast<const SfxStringItem&>(pReqArgs->
182 0 : Get( SID_ENTER_STRING )).GetValue() );
183 :
184 0 : pTabViewShell->EnterData( GetViewData()->GetCurX(),
185 : GetViewData()->GetCurY(),
186 0 : GetViewData()->GetTabNo(),
187 0 : aStr );
188 :
189 0 : ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pTabViewShell );
190 0 : if ( !pHdl || !pHdl->IsInEnterHandler() )
191 : {
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.
195 :
196 0 : pTabViewShell->UpdateInputHandler();
197 : }
198 :
199 0 : rReq.Done();
200 :
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)
204 : }
205 : }
206 0 : break;
207 :
208 : case SID_INSERT_MATRIX:
209 : {
210 0 : if ( pReqArgs )
211 : {
212 : OUString aStr = static_cast<const SfxStringItem&>(pReqArgs->
213 0 : Get( SID_INSERT_MATRIX )).GetValue();
214 0 : ScDocument* pDoc = GetViewData()->GetDocument();
215 0 : pTabViewShell->EnterMatrix( aStr, pDoc->GetGrammar() );
216 0 : rReq.Done();
217 : }
218 : }
219 0 : break;
220 :
221 : case FID_INPUTLINE_ENTER:
222 : case FID_INPUTLINE_BLOCK:
223 : case FID_INPUTLINE_MATRIX:
224 : {
225 0 : if( pReqArgs == 0 ) //XXX temporary HACK to avoid GPF
226 0 : break;
227 :
228 : const ScInputStatusItem* pStatusItem
229 : = static_cast<const ScInputStatusItem*>(&pReqArgs->
230 0 : Get( FID_INPUTLINE_STATUS ));
231 :
232 0 : ScAddress aCursorPos = pStatusItem->GetPos();
233 0 : OUString aString = pStatusItem->GetString();
234 0 : const EditTextObject* pData = pStatusItem->GetEditData();
235 :
236 0 : if (pData)
237 : {
238 0 : if (nSlot == FID_INPUTLINE_BLOCK)
239 : {
240 0 : pTabViewShell->EnterBlock( aString, pData );
241 : }
242 0 : else if ( !aString.isEmpty() && ( aString[0] == '=' || aString[0] == '+' || aString[0] == '-' ) )
243 : {
244 0 : pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, pData );
245 : }
246 : else
247 : {
248 0 : pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
249 : }
250 : }
251 : else
252 : {
253 0 : if (nSlot == FID_INPUTLINE_ENTER)
254 : {
255 0 : if (
256 0 : aCursorPos.Col() == GetViewData()->GetCurX() &&
257 0 : aCursorPos.Row() == GetViewData()->GetCurY() &&
258 0 : aCursorPos.Tab() == GetViewData()->GetTabNo()
259 : )
260 : {
261 0 : SfxStringItem aItem( SID_ENTER_STRING, aString );
262 :
263 : // SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
264 : const SfxPoolItem* aArgs[2];
265 0 : aArgs[0] = &aItem;
266 0 : aArgs[1] = NULL;
267 0 : rBindings.Execute( SID_ENTER_STRING, aArgs );
268 : }
269 : else
270 : {
271 0 : pTabViewShell->EnterData( aCursorPos.Col(),
272 : aCursorPos.Row(),
273 0 : aCursorPos.Tab(),
274 0 : aString );
275 0 : rReq.Done();
276 : }
277 : }
278 0 : else if (nSlot == FID_INPUTLINE_BLOCK)
279 : {
280 0 : pTabViewShell->EnterBlock( aString, NULL );
281 0 : rReq.Done();
282 : }
283 : else
284 : {
285 0 : ScDocument* pDoc = GetViewData()->GetDocument();
286 0 : pTabViewShell->EnterMatrix( aString, pDoc->GetGrammar() );
287 0 : rReq.Done();
288 : }
289 : }
290 :
291 : pTabViewShell->SetAutoSpellData(
292 0 : aCursorPos.Col(), aCursorPos.Row(), pStatusItem->GetMisspellRanges());
293 :
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)
297 : }
298 0 : break;
299 :
300 : case SID_OPENDLG_FUNCTION:
301 : {
302 0 : sal_uInt16 nId = SID_OPENDLG_FUNCTION;
303 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
304 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
305 :
306 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
307 0 : rReq.Ignore();
308 : }
309 0 : break;
310 :
311 : case SID_OPENDLG_CONSOLIDATE:
312 : {
313 0 : sal_uInt16 nId = ScConsolidateDlgWrapper::GetChildWindowId();
314 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
315 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
316 :
317 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
318 : }
319 0 : break;
320 :
321 : case FID_CELL_FORMAT:
322 : {
323 0 : if ( pReqArgs != NULL )
324 : {
325 :
326 : // set cell attribute without dialog:
327 :
328 : boost::scoped_ptr<SfxItemSet> pEmptySet(
329 : new SfxItemSet( *pReqArgs->GetPool(),
330 : ATTR_PATTERN_START,
331 0 : ATTR_PATTERN_END ));
332 :
333 : boost::scoped_ptr<SfxItemSet> pNewSet(
334 : new SfxItemSet( *pReqArgs->GetPool(),
335 : ATTR_PATTERN_START,
336 0 : ATTR_PATTERN_END ));
337 :
338 0 : const SfxPoolItem* pAttr = NULL;
339 0 : sal_uInt16 nWhich = 0;
340 :
341 0 : for ( nWhich=ATTR_PATTERN_START; nWhich<=ATTR_PATTERN_END; nWhich++ )
342 0 : if ( pReqArgs->GetItemState( nWhich, true, &pAttr ) == SfxItemState::SET )
343 0 : pNewSet->Put( *pAttr );
344 :
345 0 : pTabViewShell->ApplyAttributes( pNewSet.get(), pEmptySet.get() );
346 :
347 0 : pNewSet.reset();
348 0 : pEmptySet.reset();
349 :
350 0 : rReq.Done();
351 : }
352 0 : else if ( pReqArgs == NULL )
353 : {
354 0 : pTabViewShell->ExecuteCellFormatDlg( rReq );
355 : }
356 : }
357 0 : break;
358 :
359 : case SID_ENABLE_HYPHENATION:
360 0 : pTabViewShell->ExecuteCellFormatDlg(rReq, "alignment");
361 0 : break;
362 :
363 : case SID_PROPERTY_PANEL_CELLTEXT_DLG:
364 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "font" );
365 0 : break;
366 :
367 : case SID_CELL_FORMAT_BORDER:
368 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "borders" );
369 0 : break;
370 :
371 : case SID_CHAR_DLG_EFFECT:
372 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "fonteffects" );
373 0 : break;
374 :
375 : case SID_OPENDLG_SOLVE:
376 : {
377 0 : sal_uInt16 nId = ScSolverDlgWrapper::GetChildWindowId();
378 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
379 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
380 :
381 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
382 : }
383 0 : break;
384 :
385 : case SID_OPENDLG_OPTSOLVER:
386 : {
387 0 : sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
388 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
389 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
390 :
391 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
392 : }
393 0 : break;
394 :
395 : case SID_OPENDLG_TABOP:
396 : {
397 0 : sal_uInt16 nId = ScTabOpDlgWrapper::GetChildWindowId();
398 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
399 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
400 :
401 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
402 : }
403 0 : break;
404 :
405 : case SID_SCENARIOS:
406 : {
407 0 : ScDocument* pDoc = GetViewData()->GetDocument();
408 0 : ScMarkData& rMark = GetViewData()->GetMarkData();
409 0 : SCTAB nTab = GetViewData()->GetTabNo();
410 :
411 0 : if ( pDoc->IsScenario(nTab) )
412 : {
413 0 : rMark.MarkToMulti();
414 0 : if ( rMark.IsMultiMarked() )
415 : {
416 0 : if ( rReq.IsAPI()
417 0 : || RET_YES ==
418 : QueryBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
419 0 : ScGlobal::GetRscString(STR_UPDATE_SCENARIO) ).
420 0 : Execute() )
421 : {
422 0 : pTabViewShell->ExtendScenario();
423 0 : rReq.Done();
424 : }
425 : }
426 0 : else if( ! rReq.IsAPI() )
427 : {
428 : MessageDialog aErrorBox(pTabViewShell->GetDialogParent(),
429 0 : ScGlobal::GetRscString(STR_NOAREASELECTED));
430 0 : aErrorBox.Execute();
431 : }
432 : }
433 : else
434 : {
435 0 : rMark.MarkToMulti();
436 0 : if ( rMark.IsMultiMarked() )
437 : {
438 0 : SCTAB i=1;
439 0 : OUString aBaseName;
440 0 : OUString aName;
441 0 : OUString aComment;
442 0 : Color aColor;
443 : sal_uInt16 nFlags;
444 :
445 0 : OUString aTmp;
446 0 : pDoc->GetName(nTab, aTmp);
447 0 : aBaseName = aTmp;
448 0 : aBaseName += "_";
449 0 : aBaseName += ScGlobal::GetRscString(STR_SCENARIO);
450 0 : aBaseName += "_";
451 :
452 : // first test, if the prefix is recognised as valid,
453 : // else avoid only doubles
454 0 : bool bPrefix = ScDocument::ValidTabName( aBaseName );
455 : OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
456 :
457 0 : while ( pDoc->IsScenario(nTab+i) )
458 0 : i++;
459 :
460 : bool bValid;
461 : SCTAB nDummy;
462 0 : do
463 : {
464 0 : aName = aBaseName + OUString::number( i );
465 0 : if (bPrefix)
466 0 : bValid = pDoc->ValidNewTabName( aName );
467 : else
468 0 : bValid = !pDoc->GetTable( aName, nDummy );
469 0 : ++i;
470 : }
471 0 : while ( !bValid && i <= MAXTAB + 2 );
472 :
473 0 : if ( pReqArgs != NULL )
474 : {
475 0 : OUString aArgName;
476 0 : OUString aArgComment;
477 : const SfxPoolItem* pItem;
478 0 : if ( pReqArgs->GetItemState( SID_SCENARIOS, true, &pItem ) == SfxItemState::SET )
479 0 : aArgName = static_cast<const SfxStringItem*>(pItem)->GetValue();
480 0 : if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, true, &pItem ) == SfxItemState::SET )
481 0 : aArgComment = static_cast<const SfxStringItem*>(pItem)->GetValue();
482 :
483 0 : aColor = Color( COL_LIGHTGRAY ); // Default
484 0 : nFlags = 0; // not-TwoWay
485 :
486 0 : pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
487 0 : if( ! rReq.IsAPI() )
488 0 : rReq.Done();
489 : }
490 : else
491 : {
492 0 : bool bSheetProtected = pDoc->IsTabProtected(nTab);
493 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
494 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
495 :
496 0 : boost::scoped_ptr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(pTabViewShell->GetDialogParent(), aName, false, bSheetProtected));
497 : OSL_ENSURE(pNewDlg, "Dialog create fail!");
498 0 : if ( pNewDlg->Execute() == RET_OK )
499 : {
500 0 : pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
501 0 : pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
502 :
503 0 : rReq.AppendItem( SfxStringItem( SID_SCENARIOS, aName ) );
504 0 : rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
505 0 : rReq.Done();
506 0 : }
507 0 : }
508 : }
509 0 : else if( ! rReq.IsAPI() )
510 : {
511 0 : pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
512 : }
513 : }
514 : }
515 0 : break;
516 :
517 : case SID_SELECTALL:
518 : {
519 0 : pTabViewShell->SelectAll();
520 0 : rReq.Done();
521 : }
522 0 : break;
523 :
524 : case FID_ROW_HEIGHT:
525 : {
526 0 : if ( pReqArgs )
527 : {
528 0 : const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_HEIGHT ));
529 :
530 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
531 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
532 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
533 0 : if( ! rReq.IsAPI() )
534 0 : rReq.Done();
535 : }
536 : else
537 : {
538 0 : ScViewData* pData = GetViewData();
539 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
540 : sal_uInt16 nCurHeight = pData->GetDocument()->
541 : GetRowHeight( pData->GetCurY(),
542 0 : pData->GetTabNo() );
543 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
544 : assert(pFact); //ScAbstractFactory create fail!
545 :
546 : boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
547 : pTabViewShell->GetDialogParent(), "RowHeightDialog",
548 : nCurHeight, ScGlobal::nStdRowHeight,
549 0 : eMetric, 2, MAX_ROW_HEIGHT));
550 : assert(pDlg); //Dialog create fail
551 :
552 0 : if ( pDlg->Execute() == RET_OK )
553 : {
554 0 : long nVal = pDlg->GetInputValue();
555 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, (sal_uInt16)nVal );
556 :
557 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
558 0 : rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
559 0 : rReq.Done();
560 :
561 0 : }
562 : }
563 : }
564 0 : break;
565 :
566 : case FID_ROW_OPT_HEIGHT:
567 : {
568 0 : if ( pReqArgs )
569 : {
570 0 : const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_OPT_HEIGHT ));
571 :
572 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
573 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
574 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
575 0 : ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
576 :
577 0 : if( ! rReq.IsAPI() )
578 0 : rReq.Done();
579 : }
580 : else
581 : {
582 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
583 :
584 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
585 : assert(pFact); //ScAbstractFactory create fail!
586 :
587 : boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
588 : pTabViewShell->GetDialogParent(), "OptimalRowHeightDialog",
589 0 : ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT));
590 : assert(pDlg); //Dialog create fail!
591 :
592 0 : if ( pDlg->Execute() == RET_OK )
593 : {
594 0 : long nVal = pDlg->GetInputValue();
595 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
596 0 : ScGlobal::nLastRowHeightExtra = nVal;
597 :
598 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
599 0 : rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
600 0 : rReq.Done();
601 :
602 0 : }
603 : }
604 : }
605 0 : break;
606 :
607 : case FID_COL_WIDTH:
608 : {
609 0 : if ( pReqArgs )
610 : {
611 0 : const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_WIDTH ));
612 :
613 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
614 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT,
615 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
616 0 : if( ! rReq.IsAPI() )
617 0 : rReq.Done();
618 : }
619 : else
620 : {
621 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
622 0 : ScViewData* pData = GetViewData();
623 : sal_uInt16 nCurHeight = pData->GetDocument()->
624 0 : GetColWidth( pData->GetCurX(),
625 0 : pData->GetTabNo() );
626 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
627 : assert(pFact); //ScAbstractFactory create fail!
628 :
629 : boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
630 : pTabViewShell->GetDialogParent(), "ColWidthDialog", nCurHeight,
631 0 : STD_COL_WIDTH, eMetric, 2, MAX_COL_WIDTH));
632 : assert(pDlg); //Dialog create fail!
633 :
634 0 : if ( pDlg->Execute() == RET_OK )
635 : {
636 0 : long nVal = pDlg->GetInputValue();
637 0 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, (sal_uInt16)nVal );
638 :
639 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
640 0 : rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
641 0 : rReq.Done();
642 :
643 0 : }
644 : }
645 : }
646 0 : break;
647 :
648 : case FID_COL_OPT_WIDTH:
649 : {
650 0 : if ( pReqArgs )
651 : {
652 0 : const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_OPT_WIDTH ));
653 :
654 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
655 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL,
656 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
657 0 : ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
658 :
659 0 : if( ! rReq.IsAPI() )
660 0 : rReq.Done();
661 : }
662 : else
663 : {
664 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
665 :
666 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
667 : assert(pFact); //ScAbstractFactory create fail!
668 :
669 : boost::scoped_ptr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
670 : pTabViewShell->GetDialogParent(), "OptimalColWidthDialog",
671 0 : ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH, eMetric, 1, MAX_EXTRA_WIDTH));
672 : assert(pDlg); //Dialog create fail!
673 0 : if ( pDlg->Execute() == RET_OK )
674 : {
675 0 : long nVal = pDlg->GetInputValue();
676 0 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
677 0 : ScGlobal::nLastColWidthExtra = nVal;
678 :
679 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
680 0 : rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
681 0 : rReq.Done();
682 0 : }
683 : }
684 : }
685 0 : break;
686 :
687 : case FID_COL_OPT_DIRECT:
688 0 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
689 0 : rReq.Done();
690 0 : break;
691 :
692 : case FID_ROW_HIDE:
693 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
694 0 : rReq.Done();
695 0 : break;
696 : case FID_ROW_SHOW:
697 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
698 0 : rReq.Done();
699 0 : break;
700 : case FID_COL_HIDE:
701 0 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, 0 );
702 0 : rReq.Done();
703 0 : break;
704 : case FID_COL_SHOW:
705 0 : pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_SHOW, 0 );
706 0 : rReq.Done();
707 0 : break;
708 :
709 : case SID_CELL_FORMAT_RESET:
710 : {
711 0 : pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
712 0 : rReq.Done();
713 : }
714 0 : break;
715 :
716 : case FID_MERGE_ON:
717 : case FID_MERGE_OFF:
718 : case FID_MERGE_TOGGLE:
719 : {
720 0 : if ( !GetViewData()->GetDocument()->GetChangeTrack() )
721 : {
722 : // test whether to merge or to split
723 0 : bool bMerge = false;
724 0 : bool bCenter = false;
725 0 : switch( nSlot )
726 : {
727 : case FID_MERGE_ON:
728 0 : bMerge = true;
729 0 : break;
730 : case FID_MERGE_OFF:
731 0 : bMerge = false;
732 0 : break;
733 : case FID_MERGE_TOGGLE:
734 : {
735 0 : bCenter = true;
736 0 : SfxPoolItem* pItem = 0;
737 0 : if( rBindings.QueryState( nSlot, pItem ) >= SfxItemState::DEFAULT )
738 0 : bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
739 :
740 0 : delete pItem;
741 : }
742 0 : break;
743 : }
744 :
745 0 : if( bMerge )
746 : {
747 : // merge - check if to move contents of covered cells
748 0 : bool bMoveContents = false;
749 0 : bool bApi = rReq.IsAPI();
750 : const SfxPoolItem* pItem;
751 0 : if ( pReqArgs &&
752 0 : pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
753 : {
754 : OSL_ENSURE(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
755 0 : bMoveContents = static_cast<const SfxBoolItem*>(pItem)->GetValue();
756 : }
757 :
758 0 : if (pTabViewShell->MergeCells( bApi, bMoveContents, true, bCenter ))
759 : {
760 0 : if (!bApi && bMoveContents) // "yes" clicked in dialog
761 0 : rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
762 0 : rBindings.Invalidate( nSlot );
763 0 : rReq.Done();
764 : }
765 : }
766 : else
767 : {
768 : // split cells
769 0 : if (pTabViewShell->RemoveMerge())
770 : {
771 0 : rBindings.Invalidate( nSlot );
772 0 : rReq.Done();
773 : }
774 : }
775 0 : break;
776 : }
777 : }
778 0 : break;
779 :
780 : case SID_AUTOFORMAT:
781 : {
782 0 : vcl::Window* pDlgParent = pTabViewShell->GetDialogParent();
783 : SCCOL nStartCol;
784 : SCROW nStartRow;
785 : SCTAB nStartTab;
786 : SCCOL nEndCol;
787 : SCROW nEndRow;
788 : SCTAB nEndTab;
789 :
790 0 : const ScMarkData& rMark = GetViewData()->GetMarkData();
791 0 : if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
792 0 : pTabViewShell->MarkDataArea( true );
793 :
794 : GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
795 0 : nEndCol,nEndRow,nEndTab );
796 :
797 0 : if ( ( std::abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
798 0 : && ( std::abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
799 : {
800 0 : if ( pReqArgs )
801 : {
802 0 : const SfxStringItem& rNameItem = static_cast<const SfxStringItem&>(pReqArgs->Get( SID_AUTOFORMAT ));
803 0 : ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
804 0 : ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
805 0 : ScAutoFormat::const_iterator itBeg = pFormat->begin();
806 0 : size_t nIndex = std::distance(itBeg, it);
807 :
808 0 : pTabViewShell->AutoFormat( nIndex );
809 :
810 0 : if( ! rReq.IsAPI() )
811 0 : rReq.Done();
812 : }
813 : else
814 : {
815 0 : ScGlobal::ClearAutoFormat();
816 0 : boost::scoped_ptr<ScAutoFormatData> pNewEntry(pTabViewShell->CreateAutoFormatData());
817 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
818 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
819 :
820 0 : boost::scoped_ptr<AbstractScAutoFormatDlg> pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData()));
821 : OSL_ENSURE(pDlg, "Dialog create fail!");
822 :
823 0 : if ( pDlg->Execute() == RET_OK )
824 : {
825 0 : ScEditableTester aTester( pTabViewShell );
826 0 : if ( !aTester.IsEditable() )
827 : {
828 0 : pTabViewShell->ErrorMessage(aTester.GetMessageId());
829 : }
830 : else
831 : {
832 0 : pTabViewShell->AutoFormat( pDlg->GetIndex() );
833 :
834 0 : rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
835 0 : rReq.Done();
836 : }
837 0 : }
838 0 : }
839 : }
840 : else
841 : MessageDialog (pDlgParent,
842 0 : ScGlobal::GetRscString(STR_INVALID_AFAREA) ).Execute();
843 : }
844 0 : break;
845 :
846 : case SID_CANCEL:
847 : {
848 0 : if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
849 0 : pScMod->InputCancelHandler();
850 0 : else if (pTabViewShell->HasPaintBrush())
851 0 : pTabViewShell->ResetBrushDocument(); // abort format paint brush
852 0 : else if (pTabViewShell->HasHintWindow())
853 0 : pTabViewShell->RemoveHintWindow();
854 0 : else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
855 0 : ScViewUtil::SetFullScreen( *pTabViewShell, false );
856 : else
857 : {
858 : // TODO/LATER: when is this code executed?
859 0 : pTabViewShell->Escape();
860 : }
861 : }
862 0 : break;
863 :
864 : case SID_DATA_SELECT:
865 0 : pTabViewShell->StartDataSelect();
866 0 : break;
867 :
868 : case SID_DETECTIVE_FILLMODE:
869 : {
870 0 : bool bOldMode = pTabViewShell->IsAuditShell();
871 0 : pTabViewShell->SetAuditShell( !bOldMode );
872 0 : pTabViewShell->Invalidate( nSlot );
873 : }
874 0 : break;
875 :
876 : case FID_INPUTLINE_STATUS:
877 : OSL_FAIL("Execute von InputLine-Status");
878 0 : break;
879 :
880 : case SID_STATUS_DOCPOS:
881 : // Launch navigator.
882 0 : GetViewData()->GetDispatcher().Execute(
883 0 : SID_NAVIGATOR, SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
884 0 : break;
885 :
886 : case SID_MARKAREA:
887 : // called from Basic at the hidden view to select a range in the visible view
888 : OSL_FAIL("old slot SID_MARKAREA");
889 0 : break;
890 :
891 : default:
892 : OSL_FAIL("Unbekannter Slot bei ScCellShell::Execute");
893 0 : break;
894 : }
895 228 : }
896 :
897 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|