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