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 : //------------------------------------------------------------------
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(sal_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 = ((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 : String aStr( ((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 : String aStr = ((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 : = (const ScInputStatusItem*)&pReqArgs->
230 0 : Get( FID_INPUTLINE_STATUS );
231 :
232 0 : ScAddress aCursorPos = pStatusItem->GetPos();
233 0 : String aString = pStatusItem->GetString();
234 0 : const EditTextObject* pData = pStatusItem->GetEditData();
235 0 : if (pData)
236 : {
237 0 : if (nSlot == FID_INPUTLINE_BLOCK)
238 : {
239 0 : pTabViewShell->EnterBlock( aString, pData );
240 : }
241 0 : else if ( aString.Len() > 0 && ( aString.GetChar(0) == '=' || aString.GetChar(0) == '+' || aString.GetChar(0) == '-' ) )
242 : {
243 0 : pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, pData );
244 : }
245 : else
246 : {
247 0 : pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
248 : }
249 : }
250 : else
251 : {
252 0 : if (nSlot == FID_INPUTLINE_ENTER)
253 : {
254 0 : if (
255 0 : aCursorPos.Col() == GetViewData()->GetCurX() &&
256 0 : aCursorPos.Row() == GetViewData()->GetCurY() &&
257 0 : aCursorPos.Tab() == GetViewData()->GetTabNo()
258 : )
259 : {
260 0 : SfxStringItem aItem( SID_ENTER_STRING, aString );
261 :
262 : // SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
263 : const SfxPoolItem* aArgs[2];
264 0 : aArgs[0] = &aItem;
265 0 : aArgs[1] = NULL;
266 0 : rBindings.Execute( SID_ENTER_STRING, aArgs );
267 : }
268 : else
269 : {
270 0 : pTabViewShell->EnterData( aCursorPos.Col(),
271 : aCursorPos.Row(),
272 0 : aCursorPos.Tab(),
273 0 : aString );
274 0 : rReq.Done();
275 : }
276 : }
277 0 : else if (nSlot == FID_INPUTLINE_BLOCK)
278 : {
279 0 : pTabViewShell->EnterBlock( aString, NULL );
280 0 : rReq.Done();
281 : }
282 : else
283 : {
284 0 : ScDocument* pDoc = GetViewData()->GetDocument();
285 0 : pTabViewShell->EnterMatrix( aString, pDoc->GetGrammar() );
286 0 : rReq.Done();
287 : }
288 :
289 0 : }
290 :
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)
294 : }
295 0 : break;
296 :
297 : case SID_OPENDLG_FUNCTION:
298 : {
299 0 : sal_uInt16 nId = SID_OPENDLG_FUNCTION;
300 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
301 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
302 :
303 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
304 0 : rReq.Ignore();
305 : }
306 0 : break;
307 :
308 : case SID_OPENDLG_CONSOLIDATE:
309 : {
310 0 : sal_uInt16 nId = ScConsolidateDlgWrapper::GetChildWindowId();
311 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
312 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
313 :
314 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
315 : }
316 0 : break;
317 :
318 : case FID_CELL_FORMAT:
319 : {
320 0 : if ( pReqArgs != NULL )
321 : {
322 : //----------------------------------
323 : // set cell attribute without dialog:
324 : //----------------------------------
325 : SfxItemSet* pEmptySet =
326 : new SfxItemSet( *pReqArgs->GetPool(),
327 : ATTR_PATTERN_START,
328 0 : ATTR_PATTERN_END );
329 :
330 : SfxItemSet* pNewSet =
331 : new SfxItemSet( *pReqArgs->GetPool(),
332 : ATTR_PATTERN_START,
333 0 : ATTR_PATTERN_END );
334 :
335 0 : const SfxPoolItem* pAttr = NULL;
336 0 : sal_uInt16 nWhich = 0;
337 :
338 0 : for ( nWhich=ATTR_PATTERN_START; nWhich<=ATTR_PATTERN_END; nWhich++ )
339 0 : if ( pReqArgs->GetItemState( nWhich, sal_True, &pAttr ) == SFX_ITEM_SET )
340 0 : pNewSet->Put( *pAttr );
341 :
342 0 : pTabViewShell->ApplyAttributes( pNewSet, pEmptySet );
343 :
344 0 : delete pNewSet;
345 0 : delete pEmptySet;
346 :
347 0 : rReq.Done();
348 : }
349 0 : else if ( pReqArgs == NULL )
350 : {
351 0 : pTabViewShell->ExecuteCellFormatDlg( rReq );
352 : }
353 : }
354 0 : break;
355 :
356 : case SID_ENABLE_HYPHENATION:
357 0 : pTabViewShell->ExecuteCellFormatDlg(rReq, "alignment");
358 0 : break;
359 :
360 : case SID_PROPERTY_PANEL_CELLTEXT_DLG:
361 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "font" );
362 0 : break;
363 :
364 : case SID_CELL_FORMAT_BORDER:
365 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "borders" );
366 0 : break;
367 :
368 : case SID_CHAR_DLG_EFFECT:
369 0 : pTabViewShell->ExecuteCellFormatDlg( rReq, "fonteffects" );
370 0 : break;
371 :
372 : case SID_OPENDLG_SOLVE:
373 : {
374 0 : sal_uInt16 nId = ScSolverDlgWrapper::GetChildWindowId();
375 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
376 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
377 :
378 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
379 : }
380 0 : break;
381 :
382 : case SID_OPENDLG_OPTSOLVER:
383 : {
384 0 : sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
385 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
386 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
387 :
388 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
389 : }
390 0 : break;
391 :
392 : case SID_OPENDLG_TABOP:
393 : {
394 0 : sal_uInt16 nId = ScTabOpDlgWrapper::GetChildWindowId();
395 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
396 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
397 :
398 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
399 : }
400 0 : break;
401 :
402 : case SID_SCENARIOS:
403 : {
404 0 : ScDocument* pDoc = GetViewData()->GetDocument();
405 0 : ScMarkData& rMark = GetViewData()->GetMarkData();
406 0 : SCTAB nTab = GetViewData()->GetTabNo();
407 :
408 0 : if ( pDoc->IsScenario(nTab) )
409 : {
410 0 : rMark.MarkToMulti();
411 0 : if ( rMark.IsMultiMarked() )
412 : {
413 0 : if ( rReq.IsAPI()
414 0 : || RET_YES ==
415 : QueryBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
416 0 : ScGlobal::GetRscString(STR_UPDATE_SCENARIO) ).
417 0 : Execute() )
418 : {
419 0 : pTabViewShell->ExtendScenario();
420 0 : rReq.Done();
421 : }
422 : }
423 0 : else if( ! rReq.IsAPI() )
424 : {
425 : ErrorBox aErrorBox( pTabViewShell->GetDialogParent(), WinBits(WB_OK | WB_DEF_OK),
426 0 : ScGlobal::GetRscString(STR_NOAREASELECTED) );
427 0 : aErrorBox.Execute();
428 : }
429 : }
430 : else
431 : {
432 0 : rMark.MarkToMulti();
433 0 : if ( rMark.IsMultiMarked() )
434 : {
435 0 : SCTAB i=1;
436 0 : String aBaseName;
437 0 : OUString aName;
438 0 : OUString aComment;
439 0 : Color aColor;
440 : sal_uInt16 nFlags;
441 :
442 0 : OUString aTmp;
443 0 : pDoc->GetName(nTab, aTmp);
444 0 : aBaseName = aTmp;
445 0 : aBaseName += '_';
446 0 : aBaseName += ScGlobal::GetRscString(STR_SCENARIO);
447 0 : aBaseName += '_';
448 :
449 : // first test, if the prefix is recognised as valid,
450 : // else avoid only doubles
451 0 : sal_Bool bPrefix = pDoc->ValidTabName( aBaseName );
452 : OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
453 :
454 0 : while ( pDoc->IsScenario(nTab+i) )
455 0 : i++;
456 :
457 : sal_Bool bValid;
458 : SCTAB nDummy;
459 0 : do
460 : {
461 0 : aName = aBaseName + OUString::number( i );
462 0 : if (bPrefix)
463 0 : bValid = pDoc->ValidNewTabName( aName );
464 : else
465 0 : bValid = !pDoc->GetTable( aName, nDummy );
466 0 : ++i;
467 : }
468 0 : while ( !bValid && i <= MAXTAB + 2 );
469 :
470 0 : if ( pReqArgs != NULL )
471 : {
472 0 : String aArgName;
473 0 : String aArgComment;
474 : const SfxPoolItem* pItem;
475 0 : if ( pReqArgs->GetItemState( SID_SCENARIOS, sal_True, &pItem ) == SFX_ITEM_SET )
476 0 : aArgName = ((const SfxStringItem*)pItem)->GetValue();
477 0 : if ( pReqArgs->GetItemState( SID_NEW_TABLENAME, sal_True, &pItem ) == SFX_ITEM_SET )
478 0 : aArgComment = ((const SfxStringItem*)pItem)->GetValue();
479 :
480 0 : aColor = Color( COL_LIGHTGRAY ); // Default
481 0 : nFlags = 0; // not-TwoWay
482 :
483 0 : pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
484 0 : if( ! rReq.IsAPI() )
485 0 : rReq.Done();
486 : }
487 : else
488 : {
489 0 : sal_Bool bSheetProtected = pDoc->IsTabProtected(nTab);
490 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
491 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
492 :
493 0 : AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( pTabViewShell->GetDialogParent(), aName, RID_SCDLG_NEWSCENARIO, false,bSheetProtected);
494 : OSL_ENSURE(pNewDlg, "Dialog create fail!");
495 0 : if ( pNewDlg->Execute() == RET_OK )
496 : {
497 0 : pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
498 0 : pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
499 :
500 0 : rReq.AppendItem( SfxStringItem( SID_SCENARIOS, aName ) );
501 0 : rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME, aComment ) );
502 0 : rReq.Done();
503 : }
504 0 : delete pNewDlg;
505 0 : }
506 : }
507 0 : else if( ! rReq.IsAPI() )
508 : {
509 0 : pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIO);
510 : }
511 : }
512 : }
513 0 : break;
514 :
515 :
516 : case SID_SELECTALL:
517 : {
518 0 : pTabViewShell->SelectAll();
519 0 : rReq.Done();
520 : }
521 0 : break;
522 :
523 : //----------------------------------------------------------------
524 :
525 : case FID_ROW_HEIGHT:
526 : {
527 0 : if ( pReqArgs )
528 : {
529 0 : const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_HEIGHT );
530 :
531 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
532 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
533 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
534 0 : if( ! rReq.IsAPI() )
535 0 : rReq.Done();
536 : }
537 : else
538 : {
539 0 : ScViewData* pData = GetViewData();
540 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
541 : sal_uInt16 nCurHeight = pData->GetDocument()->
542 : GetRowHeight( pData->GetCurY(),
543 0 : pData->GetTabNo() );
544 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
545 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
546 :
547 : AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_MAN,
548 : nCurHeight,
549 : ScGlobal::nStdRowHeight,
550 : RID_SCDLG_ROW_MAN,
551 : eMetric,
552 : 2,
553 0 : MAX_ROW_HEIGHT);
554 : OSL_ENSURE(pDlg, "Dialog create fail!");
555 :
556 0 : if ( pDlg->Execute() == RET_OK )
557 : {
558 0 : long nVal = pDlg->GetInputValue();
559 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, (sal_uInt16)nVal );
560 :
561 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
562 0 : rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
563 0 : rReq.Done();
564 :
565 : }
566 0 : delete pDlg;
567 : }
568 : }
569 0 : break;
570 :
571 : case FID_ROW_OPT_HEIGHT:
572 : {
573 0 : if ( pReqArgs )
574 : {
575 0 : const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_ROW_OPT_HEIGHT );
576 :
577 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
578 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
579 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
580 0 : ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
581 :
582 0 : if( ! rReq.IsAPI() )
583 0 : rReq.Done();
584 : }
585 : else
586 : {
587 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
588 :
589 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
590 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
591 :
592 : AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_ROW_OPT,
593 : ScGlobal::nLastRowHeightExtra,
594 : 0,
595 : RID_SCDLG_ROW_OPT,
596 : eMetric,
597 : 1,
598 0 : MAX_EXTRA_HEIGHT);
599 : OSL_ENSURE(pDlg, "Dialog create fail!");
600 :
601 0 : if ( pDlg->Execute() == RET_OK )
602 : {
603 0 : long nVal = pDlg->GetInputValue();
604 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
605 0 : ScGlobal::nLastRowHeightExtra = nVal;
606 :
607 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
608 0 : rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
609 0 : rReq.Done();
610 :
611 : }
612 0 : delete pDlg;
613 : }
614 : }
615 0 : break;
616 :
617 : case FID_COL_WIDTH:
618 : {
619 0 : if ( pReqArgs )
620 : {
621 0 : const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_WIDTH );
622 :
623 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
624 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT,
625 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
626 0 : if( ! rReq.IsAPI() )
627 0 : rReq.Done();
628 : }
629 : else
630 : {
631 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
632 0 : ScViewData* pData = GetViewData();
633 : sal_uInt16 nCurHeight = pData->GetDocument()->
634 0 : GetColWidth( pData->GetCurX(),
635 0 : pData->GetTabNo() );
636 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
637 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
638 :
639 : AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_MAN,
640 : nCurHeight,
641 : STD_COL_WIDTH,
642 : RID_SCDLG_COL_MAN,
643 : eMetric,
644 : 2,
645 0 : MAX_COL_WIDTH);
646 : OSL_ENSURE(pDlg, "Dialog create fail!");
647 :
648 0 : if ( pDlg->Execute() == RET_OK )
649 : {
650 0 : long nVal = pDlg->GetInputValue();
651 0 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, (sal_uInt16)nVal );
652 :
653 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
654 0 : rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal)) );
655 0 : rReq.Done();
656 :
657 : }
658 0 : delete pDlg;
659 : }
660 : }
661 0 : break;
662 :
663 : case FID_COL_OPT_WIDTH:
664 : {
665 0 : if ( pReqArgs )
666 : {
667 0 : const SfxUInt16Item& rUInt16Item = (const SfxUInt16Item&)pReqArgs->Get( FID_COL_OPT_WIDTH );
668 :
669 : // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
670 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL,
671 0 : sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
672 0 : ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
673 :
674 0 : if( ! rReq.IsAPI() )
675 0 : rReq.Done();
676 : }
677 : else
678 : {
679 0 : FieldUnit eMetric = SC_MOD()->GetAppOptions().GetAppMetric();
680 :
681 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
682 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
683 :
684 : AbstractScMetricInputDlg* pDlg = pFact->CreateScMetricInputDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_COL_OPT,
685 : ScGlobal::nLastColWidthExtra,
686 : STD_EXTRA_WIDTH,
687 : RID_SCDLG_COL_OPT,
688 : eMetric,
689 : 1,
690 0 : MAX_EXTRA_WIDTH);
691 : OSL_ENSURE(pDlg, "Dialog create fail!");
692 0 : if ( pDlg->Execute() == RET_OK )
693 : {
694 0 : long nVal = pDlg->GetInputValue();
695 0 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, (sal_uInt16)nVal );
696 0 : ScGlobal::nLastColWidthExtra = nVal;
697 :
698 : // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
699 0 : rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH, (sal_uInt16)TwipsToEvenHMM(nVal) ) );
700 0 : rReq.Done();
701 : }
702 0 : delete pDlg;
703 : }
704 : }
705 0 : break;
706 :
707 : case FID_COL_OPT_DIRECT:
708 0 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH );
709 0 : rReq.Done();
710 0 : break;
711 :
712 : case FID_ROW_HIDE:
713 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
714 0 : rReq.Done();
715 0 : break;
716 : case FID_ROW_SHOW:
717 0 : pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
718 0 : rReq.Done();
719 0 : break;
720 : case FID_COL_HIDE:
721 0 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_DIRECT, 0 );
722 0 : rReq.Done();
723 0 : break;
724 : case FID_COL_SHOW:
725 0 : pTabViewShell->SetMarkedWidthOrHeight( sal_True, SC_SIZE_SHOW, 0 );
726 0 : rReq.Done();
727 0 : break;
728 :
729 : //----------------------------------------------------------------
730 :
731 :
732 : case SID_CELL_FORMAT_RESET:
733 : {
734 0 : pTabViewShell->DeleteContents( IDF_HARDATTR | IDF_EDITATTR );
735 0 : rReq.Done();
736 : }
737 0 : break;
738 :
739 : case FID_MERGE_ON:
740 : case FID_MERGE_OFF:
741 : case FID_MERGE_TOGGLE:
742 : {
743 0 : if ( !GetViewData()->GetDocument()->GetChangeTrack() )
744 : {
745 : // test whether to merge or to split
746 0 : bool bMerge = false;
747 0 : sal_Bool bCenter = false;
748 0 : switch( nSlot )
749 : {
750 : case FID_MERGE_ON:
751 0 : bMerge = true;
752 0 : break;
753 : case FID_MERGE_OFF:
754 0 : bMerge = false;
755 0 : break;
756 : case FID_MERGE_TOGGLE:
757 : {
758 0 : bCenter = true;
759 0 : SfxPoolItem* pItem = 0;
760 0 : if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
761 0 : bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
762 :
763 0 : delete pItem;
764 : }
765 0 : break;
766 : }
767 :
768 0 : if( bMerge )
769 : {
770 : // merge - check if to move contents of covered cells
771 0 : sal_Bool bMoveContents = false;
772 0 : sal_Bool bApi = rReq.IsAPI();
773 : const SfxPoolItem* pItem;
774 0 : if ( pReqArgs &&
775 0 : pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
776 : {
777 : OSL_ENSURE(pItem && pItem->ISA(SfxBoolItem), "falsches Item");
778 0 : bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
779 : }
780 :
781 0 : if (pTabViewShell->MergeCells( bApi, bMoveContents, true, bCenter ))
782 : {
783 0 : if (!bApi && bMoveContents) // "yes" clicked in dialog
784 0 : rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
785 0 : rBindings.Invalidate( nSlot );
786 0 : rReq.Done();
787 : }
788 : }
789 : else
790 : {
791 : // split cells
792 0 : if (pTabViewShell->RemoveMerge())
793 : {
794 0 : rBindings.Invalidate( nSlot );
795 0 : rReq.Done();
796 : }
797 : }
798 0 : break;
799 : }
800 : }
801 0 : break;
802 :
803 : case SID_AUTOFORMAT:
804 : {
805 0 : Window* pDlgParent = pTabViewShell->GetDialogParent();
806 : SCCOL nStartCol;
807 : SCROW nStartRow;
808 : SCTAB nStartTab;
809 : SCCOL nEndCol;
810 : SCROW nEndRow;
811 : SCTAB nEndTab;
812 :
813 0 : const ScMarkData& rMark = GetViewData()->GetMarkData();
814 0 : if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
815 0 : pTabViewShell->MarkDataArea( sal_True );
816 :
817 : GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
818 0 : nEndCol,nEndRow,nEndTab );
819 :
820 0 : if ( ( std::abs((SCsCOL)nEndCol-(SCsCOL)nStartCol) > 1 )
821 0 : && ( std::abs((SCsROW)nEndRow-(SCsROW)nStartRow) > 1 ) )
822 : {
823 0 : if ( pReqArgs )
824 : {
825 0 : const SfxStringItem& rNameItem = (const SfxStringItem&)pReqArgs->Get( SID_AUTOFORMAT );
826 0 : ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
827 0 : ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
828 0 : ScAutoFormat::const_iterator itBeg = pFormat->begin();
829 0 : size_t nIndex = std::distance(itBeg, it);
830 :
831 0 : pTabViewShell->AutoFormat( nIndex );
832 :
833 0 : if( ! rReq.IsAPI() )
834 0 : rReq.Done();
835 : }
836 : else
837 : {
838 0 : ScGlobal::ClearAutoFormat();
839 0 : ScAutoFormatData* pNewEntry = pTabViewShell->CreateAutoFormatData();
840 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
841 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
842 :
843 0 : AbstractScAutoFormatDlg* pDlg = pFact->CreateScAutoFormatDlg( pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry,GetViewData()->GetDocument(), RID_SCDLG_AUTOFORMAT );
844 : OSL_ENSURE(pDlg, "Dialog create fail!");
845 :
846 0 : if ( pDlg->Execute() == RET_OK )
847 : {
848 0 : ScEditableTester aTester( pTabViewShell );
849 0 : if ( !aTester.IsEditable() )
850 : {
851 0 : pTabViewShell->ErrorMessage(aTester.GetMessageId());
852 : }
853 : else
854 : {
855 0 : pTabViewShell->AutoFormat( pDlg->GetIndex() );
856 :
857 0 : rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) );
858 0 : rReq.Done();
859 : }
860 : }
861 0 : delete pDlg;
862 0 : delete pNewEntry;
863 : }
864 : }
865 : else
866 : ErrorBox( pDlgParent, WinBits( WB_OK | WB_DEF_OK ),
867 0 : ScGlobal::GetRscString(STR_INVALID_AFAREA) ).Execute();
868 : }
869 0 : break;
870 :
871 : case SID_CANCEL:
872 : {
873 0 : if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
874 0 : pScMod->InputCancelHandler();
875 0 : else if (pTabViewShell->HasPaintBrush())
876 0 : pTabViewShell->ResetBrushDocument(); // abort format paint brush
877 0 : else if (pTabViewShell->HasHintWindow())
878 0 : pTabViewShell->RemoveHintWindow();
879 0 : else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
880 0 : ScViewUtil::SetFullScreen( *pTabViewShell, false );
881 : else
882 : {
883 : // TODO/LATER: when is this code executed?
884 0 : pTabViewShell->Escape();
885 : }
886 : }
887 0 : break;
888 :
889 : case SID_DATA_SELECT:
890 0 : pTabViewShell->StartDataSelect();
891 0 : break;
892 :
893 : case SID_DETECTIVE_FILLMODE:
894 : {
895 0 : sal_Bool bOldMode = pTabViewShell->IsAuditShell();
896 0 : pTabViewShell->SetAuditShell( !bOldMode );
897 0 : pTabViewShell->Invalidate( nSlot );
898 : }
899 0 : break;
900 :
901 : // ----------------------------------------------------------------
902 :
903 : case FID_INPUTLINE_STATUS:
904 : OSL_FAIL("Execute von InputLine-Status");
905 0 : break;
906 :
907 : case SID_STATUS_DOCPOS:
908 : // Launch navigator.
909 0 : GetViewData()->GetDispatcher().Execute(
910 0 : SID_NAVIGATOR, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD );
911 0 : break;
912 :
913 : case SID_MARKAREA:
914 : // called from Basic at the hidden view to select a range in the visible view
915 : OSL_FAIL("old slot SID_MARKAREA");
916 0 : break;
917 :
918 : default:
919 : OSL_FAIL("Unbekannter Slot bei ScCellShell::Execute");
920 0 : break;
921 : }
922 93 : }
923 :
924 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|