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