File: | home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh.cxx |
Warning: | line 943, column 51 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | ||||
22 | #include <svl/slstitm.hxx> | |||
23 | #include <svl/stritem.hxx> | |||
24 | #include <svl/whiter.hxx> | |||
25 | #include <svtools/cliplistener.hxx> | |||
26 | #include <svtools/insdlg.hxx> | |||
27 | #include <sot/formats.hxx> | |||
28 | #include <svx/hlnkitem.hxx> | |||
29 | #include <sfx2/bindings.hxx> | |||
30 | #include <sfx2/childwin.hxx> | |||
31 | #include <sfx2/objface.hxx> | |||
32 | #include <sfx2/request.hxx> | |||
33 | #include <sfx2/viewfrm.hxx> | |||
34 | #include <vcl/EnumContext.hxx> | |||
35 | #include <vcl/svapp.hxx> | |||
36 | #include <svx/clipfmtitem.hxx> | |||
37 | ||||
38 | #include <cellsh.hxx> | |||
39 | #include <sc.hrc> | |||
40 | #include <docsh.hxx> | |||
41 | #include <attrib.hxx> | |||
42 | #include <tabvwsh.hxx> | |||
43 | #include <formulacell.hxx> | |||
44 | #include <scmod.hxx> | |||
45 | #include <globstr.hrc> | |||
46 | #include <scresid.hxx> | |||
47 | #include <transobj.hxx> | |||
48 | #include <drwtrans.hxx> | |||
49 | #include <scabstdlg.hxx> | |||
50 | #include <postit.hxx> | |||
51 | #include <cliputil.hxx> | |||
52 | #include <clipparam.hxx> | |||
53 | #include <markdata.hxx> | |||
54 | #include <gridwin.hxx> | |||
55 | ||||
56 | #define ShellClass_ScCellShell | |||
57 | #define ShellClass_CellMovement | |||
58 | #include <scslots.hxx> | |||
59 | ||||
60 | ||||
61 | SFX_IMPL_INTERFACE(ScCellShell, ScFormatShell)SfxInterface* ScCellShell::pInterface = nullptr; SfxInterface * ScCellShell::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "ScCellShell", false, GetInterfaceId(), ScFormatShell ::GetStaticInterface(), aScCellShellSlots_Impl[0], sal_uInt16 (sizeof(aScCellShellSlots_Impl) / sizeof(SfxSlot) ) ); InitInterface_Impl (); } return pInterface; } SfxInterface* ScCellShell::GetInterface () const { return GetStaticInterface(); } void ScCellShell::RegisterInterface (const SfxModule* pMod) { GetStaticInterface()->Register(pMod ); } | |||
62 | ||||
63 | void ScCellShell::InitInterface_Impl() | |||
64 | { | |||
65 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, | |||
66 | SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server, | |||
67 | ToolbarId::Objectbar_Format); | |||
68 | ||||
69 | GetStaticInterface()->RegisterPopupMenu("cell"); | |||
70 | } | |||
71 | ||||
72 | ScCellShell::ScCellShell(ScViewData& rData, const VclPtr<vcl::Window>& frameWin) : | |||
73 | ScFormatShell(&rData), | |||
74 | pImpl( new CellShell_Impl() ), | |||
75 | bPastePossible(false), | |||
76 | pFrameWin(frameWin) | |||
77 | { | |||
78 | SetName("Cell"); | |||
79 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Cell)); | |||
80 | } | |||
81 | ||||
82 | ScCellShell::~ScCellShell() | |||
83 | { | |||
84 | if ( pImpl->m_xClipEvtLstnr.is() ) | |||
85 | { | |||
86 | pImpl->m_xClipEvtLstnr->RemoveListener( GetViewData()->GetActiveWin() ); | |||
87 | ||||
88 | // The listener may just now be waiting for the SolarMutex and call the link | |||
89 | // afterwards, in spite of RemoveListener. So the link has to be reset, too. | |||
90 | pImpl->m_xClipEvtLstnr->ClearCallbackLink(); | |||
91 | ||||
92 | pImpl->m_xClipEvtLstnr.clear(); | |||
93 | } | |||
94 | ||||
95 | pImpl->m_pLinkedDlg.disposeAndClear(); | |||
96 | delete pImpl->m_pRequest; | |||
97 | } | |||
98 | ||||
99 | void ScCellShell::GetBlockState( SfxItemSet& rSet ) | |||
100 | { | |||
101 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
102 | ScRange aMarkRange; | |||
103 | ScMarkType eMarkType = GetViewData()->GetSimpleArea( aMarkRange ); | |||
104 | bool bSimpleArea = (eMarkType == SC_MARK_SIMPLE); | |||
105 | bool bOnlyNotBecauseOfMatrix; | |||
106 | bool bEditable = pTabViewShell->SelectionEditable( &bOnlyNotBecauseOfMatrix ); | |||
107 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
108 | ScDocShell* pDocShell = GetViewData()->GetDocShell(); | |||
109 | ScMarkData& rMark = GetViewData()->GetMarkData(); | |||
110 | SCCOL nCol1, nCol2; | |||
111 | SCROW nRow1, nRow2; | |||
112 | nCol1 = aMarkRange.aStart.Col(); | |||
113 | nRow1 = aMarkRange.aStart.Row(); | |||
114 | nCol2 = aMarkRange.aEnd.Col(); | |||
115 | nRow2 = aMarkRange.aEnd.Row(); | |||
116 | ||||
117 | SfxWhichIter aIter(rSet); | |||
118 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
119 | while ( nWhich ) | |||
120 | { | |||
121 | bool bDisable = false; | |||
122 | bool bNeedEdit = true; // need selection be editable? | |||
123 | switch ( nWhich ) | |||
124 | { | |||
125 | case FID_FILL_TO_BOTTOM((((26000 + 200) + 20)) + 4): // fill to top / bottom | |||
126 | { | |||
127 | bDisable = !bSimpleArea || (nRow1 == 0 && nRow2 == 0); | |||
128 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
129 | bDisable = true; | |||
130 | if ( !bDisable && bEditable ) | |||
131 | { // do not damage matrix | |||
132 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
133 | nCol1, nRow1, nCol2, nRow1, rMark ); // first row | |||
134 | } | |||
135 | } | |||
136 | break; | |||
137 | case FID_FILL_TO_TOP((((26000 + 200) + 20)) + 6): | |||
138 | { | |||
139 | bDisable = (!bSimpleArea) || (nRow1 == rDoc.MaxRow() && nRow2 == rDoc.MaxRow()); | |||
140 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
141 | bDisable = true; | |||
142 | if ( !bDisable && bEditable ) | |||
143 | { // do not damage matrix | |||
144 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
145 | nCol1, nRow2, nCol2, nRow2, rMark ); // last row | |||
146 | } | |||
147 | } | |||
148 | break; | |||
149 | case FID_FILL_TO_RIGHT((((26000 + 200) + 20)) + 5): // fill to left / right | |||
150 | { | |||
151 | bDisable = !bSimpleArea || (nCol1 == 0 && nCol2 == 0); | |||
152 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
153 | bDisable = true; | |||
154 | if ( !bDisable && bEditable ) | |||
155 | { // do not damage matrix | |||
156 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
157 | nCol1, nRow1, nCol1, nRow2, rMark ); // first column | |||
158 | } | |||
159 | } | |||
160 | break; | |||
161 | case FID_FILL_TO_LEFT((((26000 + 200) + 20)) + 7): | |||
162 | { | |||
163 | bDisable = (!bSimpleArea) || (nCol1 == rDoc.MaxCol() && nCol2 == rDoc.MaxCol()); | |||
164 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
165 | bDisable = true; | |||
166 | if ( !bDisable && bEditable ) | |||
167 | { // do not damage matrix | |||
168 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
169 | nCol2, nRow1, nCol2, nRow2, rMark ); // last column | |||
170 | } | |||
171 | } | |||
172 | break; | |||
173 | ||||
174 | case SID_RANDOM_NUMBER_GENERATOR_DIALOG((26000 + 100) + 70): | |||
175 | bDisable = !bSimpleArea || GetViewData()->SelectionForbidsCellFill(); | |||
176 | break; | |||
177 | case SID_SAMPLING_DIALOG((26000 + 100) + 71): | |||
178 | case SID_DESCRIPTIVE_STATISTICS_DIALOG((26000 + 100) + 72): | |||
179 | case SID_ANALYSIS_OF_VARIANCE_DIALOG((26000 + 100) + 73): | |||
180 | case SID_CORRELATION_DIALOG((26000 + 100) + 74): | |||
181 | case SID_COVARIANCE_DIALOG((26000 + 100) + 75): | |||
182 | { | |||
183 | bDisable = !bSimpleArea; | |||
184 | } | |||
185 | break; | |||
186 | ||||
187 | case FID_FILL_SERIES((((26000 + 200) + 20)) + 9): // fill block | |||
188 | case SID_OPENDLG_TABOP((26000 + 100) + 54): // multiple-cell operations, are at least 2 cells marked? | |||
189 | if (rDoc.GetChangeTrack()!=nullptr &&nWhich ==SID_OPENDLG_TABOP((26000 + 100) + 54)) | |||
190 | bDisable = true; | |||
191 | else | |||
192 | bDisable = (!bSimpleArea) || (nCol1 == nCol2 && nRow1 == nRow2); | |||
193 | ||||
194 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
195 | bDisable = true; | |||
196 | ||||
197 | if ( !bDisable && bEditable && nWhich == FID_FILL_SERIES((((26000 + 200) + 20)) + 9) ) | |||
198 | { // do not damage matrix | |||
199 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
200 | nCol1, nRow1, nCol2, nRow1, rMark ) // first row | |||
201 | || rDoc.HasSelectedBlockMatrixFragment( | |||
202 | nCol1, nRow2, nCol2, nRow2, rMark ) // last row | |||
203 | || rDoc.HasSelectedBlockMatrixFragment( | |||
204 | nCol1, nRow1, nCol1, nRow2, rMark ) // first column | |||
205 | || rDoc.HasSelectedBlockMatrixFragment( | |||
206 | nCol2, nRow1, nCol2, nRow2, rMark ); // last column | |||
207 | } | |||
208 | break; | |||
209 | case FID_FILL_SINGLE_EDIT((((26000 + 200) + 20)) + 10): | |||
210 | bDisable = false; | |||
211 | break; | |||
212 | case SID_CUT(5000 + 710): // cut | |||
213 | bDisable = !bSimpleArea || GetObjectShell()->isContentExtractionLocked(); | |||
214 | break; | |||
215 | case FID_INS_CELL((((((((26000 + 200) + 20)) + 20)) + 20)) + 6): // insert cells, just simple selection | |||
216 | bDisable = (!bSimpleArea); | |||
217 | break; | |||
218 | ||||
219 | case SID_PASTE(5000 + 712): | |||
220 | case SID_PASTE_SPECIAL(5000 + 311): | |||
221 | case SID_PASTE_UNFORMATTED(5000 + 314): | |||
222 | case SID_PASTE_ONLY_VALUE(5000 + 804): | |||
223 | case SID_PASTE_ONLY_TEXT(5000 + 802): | |||
224 | case SID_PASTE_ONLY_FORMULA(5000 + 803): | |||
225 | case SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805): | |||
226 | bDisable = GetViewData()->SelectionForbidsCellFill(); | |||
227 | break; | |||
228 | ||||
229 | case FID_INS_ROW((((((((26000 + 200) + 20)) + 20)) + 20)) + 7): | |||
230 | case FID_INS_ROWS_BEFORE((((((((26000 + 200) + 20)) + 20)) + 20)) + 22): // insert rows | |||
231 | case FID_INS_ROWS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 20): | |||
232 | { | |||
233 | sc::ColRowEditAction eAction = sc::ColRowEditAction::InsertRowsBefore; | |||
234 | if (nWhich == FID_INS_ROWS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 20)) | |||
235 | eAction = sc::ColRowEditAction::InsertRowsAfter; | |||
236 | ||||
237 | bDisable = (!bSimpleArea) || GetViewData()->SimpleColMarked(); | |||
238 | if (!bEditable && nCol1 == 0 && nCol2 == rDoc.MaxCol()) | |||
239 | { | |||
240 | // See if row insertions are allowed. | |||
241 | bEditable = rDoc.IsEditActionAllowed(eAction, rMark, nRow1, nRow2); | |||
242 | } | |||
243 | break; | |||
244 | } | |||
245 | case FID_INS_CELLSDOWN((((((((26000 + 200) + 20)) + 20)) + 20)) + 18): | |||
246 | bDisable = (!bSimpleArea) || GetViewData()->SimpleColMarked(); | |||
247 | break; | |||
248 | ||||
249 | case FID_INS_COLUMN((((((((26000 + 200) + 20)) + 20)) + 20)) + 8): | |||
250 | case FID_INS_COLUMNS_BEFORE((((((((26000 + 200) + 20)) + 20)) + 20)) + 23): // insert columns | |||
251 | case FID_INS_COLUMNS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 21): | |||
252 | { | |||
253 | sc::ColRowEditAction eAction = sc::ColRowEditAction::InsertColumnsBefore; | |||
254 | if (nWhich == FID_INS_COLUMNS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 21)) | |||
255 | eAction = sc::ColRowEditAction::InsertColumnsAfter; | |||
256 | ||||
257 | bDisable = (!bSimpleArea) || GetViewData()->SimpleRowMarked(); | |||
258 | if (!bEditable && nRow1 == 0 && nRow2 == rDoc.MaxRow()) | |||
259 | { | |||
260 | // See if row insertions are allowed. | |||
261 | bEditable = rDoc.IsEditActionAllowed(eAction, rMark, nCol1, nCol2); | |||
262 | } | |||
263 | break; | |||
264 | } | |||
265 | case FID_INS_CELLSRIGHT((((((((26000 + 200) + 20)) + 20)) + 20)) + 19): | |||
266 | bDisable = (!bSimpleArea) || GetViewData()->SimpleRowMarked(); | |||
267 | break; | |||
268 | ||||
269 | case SID_COPY(5000 + 711): // copy | |||
270 | // not editable because of matrix only? Do not damage matrix | |||
271 | //! is not called, when protected AND matrix, we will have | |||
272 | //! to live with this... is caught in Copy-Routine, otherwise | |||
273 | //! work is to be done once more | |||
274 | if ( bEditable || !bOnlyNotBecauseOfMatrix ) | |||
275 | bNeedEdit = false; // allowed when protected/ReadOnly | |||
276 | bDisable = GetObjectShell()->isContentExtractionLocked(); | |||
277 | break; | |||
278 | ||||
279 | case SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ): // Autoformat, at least 3x3 selected | |||
280 | bDisable = (!bSimpleArea) | |||
281 | || ((nCol2 - nCol1) < 2) || ((nRow2 - nRow1) < 2); | |||
282 | break; | |||
283 | ||||
284 | case SID_CELL_FORMAT_RESET((26000) + 67) : | |||
285 | case FID_CELL_FORMAT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25))) : | |||
286 | case SID_ENABLE_HYPHENATION((26000) + 87) : | |||
287 | // not editable because of matrix only? Attribute ok nonetheless | |||
288 | if ( !bEditable && bOnlyNotBecauseOfMatrix ) | |||
289 | bNeedEdit = false; | |||
290 | break; | |||
291 | ||||
292 | case FID_VALIDATION((((26000 + 521) + 50))+54): | |||
293 | { | |||
294 | if ( pDocShell && pDocShell->IsDocShared() ) | |||
295 | { | |||
296 | bDisable = true; | |||
297 | } | |||
298 | } | |||
299 | break; | |||
300 | case SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ): | |||
301 | case SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ): | |||
302 | case SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ): | |||
303 | case SID_TRANSLITERATE_KATAKANA( 10000 + 917 ): | |||
304 | ScViewUtil::HideDisabledSlot( rSet, GetViewData()->GetBindings(), nWhich ); | |||
305 | break; | |||
306 | case SID_CONVERT_FORMULA_TO_VALUE((26000 + 200) + 5): | |||
307 | { | |||
308 | // Check and see if the marked range has at least one formula cell. | |||
309 | bDisable = !rDoc.HasFormulaCell(aMarkRange); | |||
310 | } | |||
311 | break; | |||
312 | } | |||
313 | if (!bDisable && bNeedEdit && !bEditable) | |||
314 | bDisable = true; | |||
315 | ||||
316 | if (bDisable) | |||
317 | rSet.DisableItem(nWhich); | |||
318 | else if (nWhich == SID_ENABLE_HYPHENATION((26000) + 87)) | |||
319 | { | |||
320 | // toggle slots need a bool item | |||
321 | rSet.Put( SfxBoolItem( nWhich, false ) ); | |||
322 | } | |||
323 | nWhich = aIter.NextWhich(); | |||
324 | } | |||
325 | } | |||
326 | ||||
327 | // functions, disabled depending on cursor position | |||
328 | // Default: | |||
329 | // SID_INSERT_POSTIT, SID_CHARMAP, SID_OPENDLG_FUNCTION | |||
330 | ||||
331 | void ScCellShell::GetCellState( SfxItemSet& rSet ) | |||
332 | { | |||
333 | ScDocShell* pDocShell = GetViewData()->GetDocShell(); | |||
334 | ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument(); | |||
335 | ScAddress aCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), | |||
336 | GetViewData()->GetTabNo() ); | |||
337 | SfxWhichIter aIter(rSet); | |||
338 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
339 | while ( nWhich ) | |||
340 | { | |||
341 | bool bDisable = false; | |||
342 | bool bNeedEdit = true; // need cursor position be editable? | |||
343 | switch ( nWhich ) | |||
344 | { | |||
345 | case SID_THESAURUS( 10000 + 245 ): | |||
346 | { | |||
347 | CellType eType = rDoc.GetCellType( aCursor ); | |||
348 | bDisable = ( eType != CELLTYPE_STRING && eType != CELLTYPE_EDIT); | |||
349 | if (!bDisable) | |||
350 | { | |||
351 | // test for available languages | |||
352 | LanguageType nLang = ScViewUtil::GetEffLanguage( rDoc, aCursor ); | |||
353 | bDisable = !ScModule::HasThesaurusLanguage( nLang ); | |||
354 | } | |||
355 | } | |||
356 | break; | |||
357 | case SID_OPENDLG_FUNCTION((26000 + 100) + 52): | |||
358 | { | |||
359 | ScMarkData aMarkData = GetViewData()->GetMarkData(); | |||
360 | aMarkData.MarkToSimple(); | |||
361 | ScRange aRange; | |||
362 | aMarkData.GetMarkArea(aRange); | |||
363 | if(aMarkData.IsMarked()) | |||
364 | { | |||
365 | if (!rDoc.IsBlockEditable( aCursor.Tab(), aRange.aStart.Col(),aRange.aStart.Row(), | |||
366 | aRange.aEnd.Col(),aRange.aEnd.Row() )) | |||
367 | { | |||
368 | bDisable = true; | |||
369 | } | |||
370 | bNeedEdit=false; | |||
371 | } | |||
372 | ||||
373 | } | |||
374 | break; | |||
375 | case SID_INSERT_POSTIT( 10000 + 1101 ): | |||
376 | { | |||
377 | ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); | |||
378 | if( rDoc.GetNote(aPos) ) | |||
379 | { | |||
380 | bDisable = true; | |||
381 | } | |||
382 | else | |||
383 | { | |||
384 | bDisable = false; | |||
385 | if ( pDocShell && pDocShell->IsDocShared() ) | |||
386 | { | |||
387 | bDisable = true; | |||
388 | } | |||
389 | } | |||
390 | } | |||
391 | break; | |||
392 | case SID_EDIT_POSTIT( 10000 + 1158 ): | |||
393 | { | |||
394 | ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); | |||
395 | bDisable = rDoc.GetNote(aPos) == nullptr; | |||
396 | } | |||
397 | break; | |||
398 | } | |||
399 | if (!bDisable && bNeedEdit) | |||
400 | if (!rDoc.IsBlockEditable( aCursor.Tab(), aCursor.Col(),aCursor.Row(), | |||
401 | aCursor.Col(),aCursor.Row() )) | |||
402 | bDisable = true; | |||
403 | if (bDisable) | |||
404 | rSet.DisableItem(nWhich); | |||
405 | nWhich = aIter.NextWhich(); | |||
406 | } | |||
407 | } | |||
408 | ||||
409 | static bool lcl_TestFormat( SvxClipboardFormatItem& rFormats, const TransferableDataHelper& rDataHelper, | |||
410 | SotClipboardFormatId nFormatId ) | |||
411 | { | |||
412 | if ( rDataHelper.HasFormat( nFormatId ) ) | |||
413 | { | |||
414 | // translated format name strings are no longer inserted here, | |||
415 | // handled by "paste special" dialog / toolbox controller instead. | |||
416 | // Only the object type name has to be set here: | |||
417 | OUString aStrVal; | |||
418 | if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE ) | |||
419 | { | |||
420 | TransferableObjectDescriptor aDesc; | |||
421 | if ( const_cast<TransferableDataHelper&>(rDataHelper).GetTransferableObjectDescriptor( | |||
422 | SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc ) ) | |||
423 | aStrVal = aDesc.maTypeName; | |||
424 | } | |||
425 | else if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE_OLE | |||
426 | || nFormatId == SotClipboardFormatId::EMBEDDED_OBJ_OLE ) | |||
427 | { | |||
428 | OUString aSource; | |||
429 | SvPasteObjectHelper::GetEmbeddedName( rDataHelper, aStrVal, aSource, nFormatId ); | |||
430 | } | |||
431 | ||||
432 | if ( !aStrVal.isEmpty() ) | |||
433 | rFormats.AddClipbrdFormat( nFormatId, aStrVal ); | |||
434 | else | |||
435 | rFormats.AddClipbrdFormat( nFormatId ); | |||
436 | ||||
437 | return true; | |||
438 | } | |||
439 | ||||
440 | return false; | |||
441 | } | |||
442 | ||||
443 | void ScCellShell::GetPossibleClipboardFormats( SvxClipboardFormatItem& rFormats ) | |||
444 | { | |||
445 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
446 | bool bDraw = ScDrawTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pWin)) != nullptr; | |||
447 | ||||
448 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) ); | |||
449 | ||||
450 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::DRAWING ); | |||
451 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::SVXB ); | |||
452 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::GDIMETAFILE ); | |||
453 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::PNG ); | |||
454 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BITMAP ); | |||
455 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBED_SOURCE ); | |||
456 | ||||
457 | if ( !bDraw ) | |||
458 | { | |||
459 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::LINK ); | |||
460 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::STRING ); | |||
461 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::STRING_TSVC ); | |||
462 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::DIF ); | |||
463 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::RTF ); | |||
464 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::RICHTEXT ); | |||
465 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::HTML ); | |||
466 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::HTML_SIMPLE ); | |||
467 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BIFF_8 ); | |||
468 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BIFF_5 ); | |||
469 | } | |||
470 | ||||
471 | if ( !lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBED_SOURCE_OLE ) ) | |||
472 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBEDDED_OBJ_OLE ); | |||
473 | } | |||
474 | ||||
475 | // insert, insert contents | |||
476 | ||||
477 | static bool lcl_IsCellPastePossible( const TransferableDataHelper& rData ) | |||
478 | { | |||
479 | bool bPossible = false; | |||
480 | css::uno::Reference< css::datatransfer::XTransferable2 > xTransferable(rData.GetXTransferable(), css::uno::UNO_QUERY); | |||
481 | if ( ScTransferObj::GetOwnClipboard(xTransferable) || ScDrawTransferObj::GetOwnClipboard(xTransferable) ) | |||
482 | bPossible = true; | |||
483 | else | |||
484 | { | |||
485 | if ( rData.HasFormat( SotClipboardFormatId::PNG ) || | |||
486 | rData.HasFormat( SotClipboardFormatId::BITMAP ) || | |||
487 | rData.HasFormat( SotClipboardFormatId::GDIMETAFILE ) || | |||
488 | rData.HasFormat( SotClipboardFormatId::SVXB ) || | |||
489 | rData.HasFormat( SotClipboardFormatId::PRIVATE ) || | |||
490 | rData.HasFormat( SotClipboardFormatId::RTF ) || | |||
491 | rData.HasFormat( SotClipboardFormatId::RICHTEXT ) || | |||
492 | rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE ) || | |||
493 | rData.HasFormat( SotClipboardFormatId::LINK_SOURCE ) || | |||
494 | rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE_OLE ) || | |||
495 | rData.HasFormat( SotClipboardFormatId::LINK_SOURCE_OLE ) || | |||
496 | rData.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ_OLE ) || | |||
497 | rData.HasFormat( SotClipboardFormatId::STRING ) || | |||
498 | rData.HasFormat( SotClipboardFormatId::STRING_TSVC ) || | |||
499 | rData.HasFormat( SotClipboardFormatId::SYLK ) || | |||
500 | rData.HasFormat( SotClipboardFormatId::LINK ) || | |||
501 | rData.HasFormat( SotClipboardFormatId::HTML ) || | |||
502 | rData.HasFormat( SotClipboardFormatId::HTML_SIMPLE ) || | |||
503 | rData.HasFormat( SotClipboardFormatId::DIF ) ) | |||
504 | { | |||
505 | bPossible = true; | |||
506 | } | |||
507 | } | |||
508 | return bPossible; | |||
509 | } | |||
510 | ||||
511 | bool ScCellShell::HasClipboardFormat( SotClipboardFormatId nFormatId ) | |||
512 | { | |||
513 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
514 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin )); | |||
515 | return aDataHelper.HasFormat( nFormatId ); | |||
516 | } | |||
517 | ||||
518 | IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )void ScCellShell::LinkStubClipboardChanged(void * instance, TransferableDataHelper * data) { return static_cast<ScCellShell *>(instance)-> ClipboardChanged(data); } void ScCellShell::ClipboardChanged( TransferableDataHelper* pDataHelper) | |||
519 | { | |||
520 | bPastePossible = lcl_IsCellPastePossible( *pDataHelper ); | |||
521 | ||||
522 | SfxBindings& rBindings = GetViewData()->GetBindings(); | |||
523 | rBindings.Invalidate( SID_PASTE(5000 + 712) ); | |||
524 | rBindings.Invalidate( SID_PASTE_SPECIAL(5000 + 311) ); | |||
525 | rBindings.Invalidate( SID_PASTE_UNFORMATTED(5000 + 314) ); | |||
526 | rBindings.Invalidate( SID_PASTE_ONLY_VALUE(5000 + 804) ); | |||
527 | rBindings.Invalidate( SID_PASTE_ONLY_TEXT(5000 + 802) ); | |||
528 | rBindings.Invalidate( SID_PASTE_ONLY_FORMULA(5000 + 803) ); | |||
529 | rBindings.Invalidate( SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805) ); | |||
530 | rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
531 | } | |||
532 | ||||
533 | namespace { | |||
534 | ||||
535 | bool checkDestRanges(ScViewData& rViewData) | |||
536 | { | |||
537 | ScRange aDummy; | |||
538 | ScMarkType eMarkType = rViewData.GetSimpleArea( aDummy); | |||
539 | if (eMarkType != SC_MARK_MULTI) | |||
540 | { | |||
541 | // Single destination range. | |||
542 | if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) | |||
543 | return false; | |||
544 | } | |||
545 | ||||
546 | if (rViewData.SelectionForbidsCellFill()) | |||
547 | return false; | |||
548 | ||||
549 | // Multiple destination ranges. | |||
550 | ||||
551 | ScDocument& rDoc = rViewData.GetDocument(); | |||
552 | vcl::Window* pWin = rViewData.GetActiveWin(); | |||
553 | if (!pWin) | |||
554 | return false; | |||
555 | ||||
556 | const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pWin)); | |||
557 | if (!pOwnClip) | |||
558 | // If it's not a Calc document, we won't be picky. | |||
559 | return true; | |||
560 | ||||
561 | ScDocument* pClipDoc = pOwnClip->GetDocument(); | |||
562 | if (!pClipDoc) | |||
563 | return false; | |||
564 | ||||
565 | ScRange aSrcRange = pClipDoc->GetClipParam().getWholeRange(); | |||
566 | SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1; | |||
567 | SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1; | |||
568 | ||||
569 | ScMarkData aMark = rViewData.GetMarkData(); | |||
570 | ScRangeList aRanges; | |||
571 | aMark.MarkToSimple(); | |||
572 | aMark.FillRangeListWithMarks(&aRanges, false); | |||
573 | ||||
574 | return ScClipUtil::CheckDestRanges(rDoc, nColSize, nRowSize, aMark, aRanges); | |||
575 | } | |||
576 | ||||
577 | } | |||
578 | ||||
579 | void ScCellShell::GetClipState( SfxItemSet& rSet ) | |||
580 | { | |||
581 | // SID_PASTE | |||
582 | // SID_PASTE_SPECIAL | |||
583 | // SID_PASTE_UNFORMATTED | |||
584 | // SID_CLIPBOARD_FORMAT_ITEMS | |||
585 | ||||
586 | if ( !pImpl->m_xClipEvtLstnr.is() ) | |||
587 | { | |||
588 | // create listener | |||
589 | pImpl->m_xClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScCellShell, ClipboardChanged )::tools::detail::makeLink( ::tools::detail::castTo<ScCellShell *>(this), &ScCellShell::LinkStubClipboardChanged) ); | |||
590 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
591 | pImpl->m_xClipEvtLstnr->AddListener( pWin ); | |||
592 | ||||
593 | // get initial state | |||
594 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) ); | |||
595 | bPastePossible = lcl_IsCellPastePossible( aDataHelper ); | |||
596 | } | |||
597 | ||||
598 | bool bDisable = !bPastePossible; | |||
599 | ||||
600 | // cell protection / multiple selection | |||
601 | ||||
602 | if (!bDisable) | |||
603 | { | |||
604 | SCCOL nCol = GetViewData()->GetCurX(); | |||
605 | SCROW nRow = GetViewData()->GetCurY(); | |||
606 | SCTAB nTab = GetViewData()->GetTabNo(); | |||
607 | ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument(); | |||
608 | if (!rDoc.IsBlockEditable( nTab, nCol,nRow, nCol,nRow )) | |||
609 | bDisable = true; | |||
610 | ||||
611 | if (!bDisable && !checkDestRanges(*GetViewData())) | |||
612 | bDisable = true; | |||
613 | } | |||
614 | ||||
615 | if (bDisable) | |||
616 | { | |||
617 | rSet.DisableItem( SID_PASTE(5000 + 712) ); | |||
618 | rSet.DisableItem( SID_PASTE_SPECIAL(5000 + 311) ); | |||
619 | rSet.DisableItem( SID_PASTE_UNFORMATTED(5000 + 314) ); | |||
620 | rSet.DisableItem( SID_PASTE_ONLY_VALUE(5000 + 804) ); | |||
621 | rSet.DisableItem( SID_PASTE_ONLY_TEXT(5000 + 802) ); | |||
622 | rSet.DisableItem( SID_PASTE_ONLY_FORMULA(5000 + 803) ); | |||
623 | rSet.DisableItem( SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805) ); | |||
624 | rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
625 | } | |||
626 | else if ( rSet.GetItemState( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ) != SfxItemState::UNKNOWN ) | |||
627 | { | |||
628 | SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
629 | GetPossibleClipboardFormats( aFormats ); | |||
630 | rSet.Put( aFormats ); | |||
631 | } | |||
632 | } | |||
633 | ||||
634 | // only SID_HYPERLINK_GETLINK: | |||
635 | ||||
636 | void ScCellShell::GetHLinkState( SfxItemSet& rSet ) | |||
637 | { | |||
638 | // always return an item (or inserting will be disabled) | |||
639 | // if the cell at the cursor contains only a link, return that link | |||
640 | ||||
641 | SvxHyperlinkItem aHLinkItem; | |||
642 | if ( !GetViewData()->GetView()->HasBookmarkAtCursor( &aHLinkItem ) ) | |||
643 | { | |||
644 | //! put selected text into item? | |||
645 | } | |||
646 | ||||
647 | rSet.Put(aHLinkItem); | |||
648 | } | |||
649 | ||||
650 | void ScCellShell::GetState(SfxItemSet &rSet) | |||
651 | { | |||
652 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
653 | ScDocShell* pDocSh = GetViewData()->GetDocShell(); | |||
| ||||
654 | ScViewData* pData = GetViewData(); | |||
655 | ScDocument& rDoc = pData->GetDocument(); | |||
656 | ScMarkData& rMark = pData->GetMarkData(); | |||
657 | SCCOL nPosX = pData->GetCurX(); | |||
658 | SCROW nPosY = pData->GetCurY(); | |||
659 | SCTAB nTab = pData->GetTabNo(); | |||
660 | ||||
661 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
662 | SCTAB nTabSelCount = rMark.GetSelectCount(); | |||
663 | ||||
664 | SfxWhichIter aIter(rSet); | |||
665 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
666 | while ( nWhich ) | |||
667 | { | |||
668 | switch ( nWhich ) | |||
669 | { | |||
670 | case SID_DETECTIVE_REFRESH((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+14): | |||
671 | if (!rDoc.HasDetectiveOperations()) | |||
672 | rSet.DisableItem( nWhich ); | |||
673 | break; | |||
674 | ||||
675 | case SID_RANGE_ADDRESS((((26000 + 521) + 50))+47): | |||
676 | { | |||
677 | ScRange aRange; | |||
678 | if ( pData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE ) | |||
679 | { | |||
680 | OUString aStr(aRange.Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D)); | |||
681 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
682 | } | |||
683 | } | |||
684 | break; | |||
685 | ||||
686 | case SID_RANGE_NOTETEXT((((26000 + 521) + 50))+52): | |||
687 | { | |||
688 | // always take cursor position, do not use top-left cell of selection | |||
689 | OUString aNoteText; | |||
690 | if ( const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab) ) | |||
691 | aNoteText = pNote->GetText(); | |||
692 | rSet.Put( SfxStringItem( nWhich, aNoteText ) ); | |||
693 | } | |||
694 | break; | |||
695 | ||||
696 | case SID_RANGE_ROW((((26000 + 521) + 50))+20): | |||
697 | rSet.Put( SfxInt32Item( nWhich, nPosY+1 ) ); | |||
698 | break; | |||
699 | ||||
700 | case SID_RANGE_COL((((26000 + 521) + 50))+21): | |||
701 | rSet.Put( SfxInt16Item( nWhich, nPosX+1 ) ); | |||
702 | break; | |||
703 | ||||
704 | case SID_RANGE_TABLE((((26000 + 521) + 50))+22): | |||
705 | rSet.Put( SfxInt16Item( nWhich, nTab+1 ) ); | |||
706 | break; | |||
707 | ||||
708 | case SID_RANGE_FORMULA((((26000 + 521) + 50))+24): | |||
709 | { | |||
710 | OUString aString; | |||
711 | rDoc.GetFormula( nPosX, nPosY, nTab, aString ); | |||
712 | if( aString.isEmpty() ) | |||
713 | { | |||
714 | rDoc.GetInputString( nPosX, nPosY, nTab, aString ); | |||
715 | } | |||
716 | rSet.Put( SfxStringItem( nWhich, aString ) ); | |||
717 | } | |||
718 | break; | |||
719 | ||||
720 | case SID_RANGE_TEXTVALUE((((26000 + 521) + 50))+26): | |||
721 | { | |||
722 | OUString aString = rDoc.GetString(nPosX, nPosY, nTab); | |||
723 | rSet.Put( SfxStringItem( nWhich, aString ) ); | |||
724 | } | |||
725 | break; | |||
726 | ||||
727 | case SID_STATUS_SELMODE((26000 + 100) + 16): | |||
728 | { | |||
729 | /* 0: STD Click cancels Sel | |||
730 | * 1: ER Click extends selection | |||
731 | * 2: ERG Click defines further selection | |||
732 | */ | |||
733 | sal_uInt16 nMode = pTabViewShell->GetLockedModifiers(); | |||
734 | ||||
735 | switch ( nMode ) | |||
736 | { | |||
737 | case KEY_SHIFT: nMode = 1; break; | |||
738 | case KEY_MOD1: nMode = 2; break; // Control-key | |||
739 | case 0: | |||
740 | default: | |||
741 | nMode = 0; | |||
742 | } | |||
743 | ||||
744 | rSet.Put( SfxUInt16Item( nWhich, nMode ) ); | |||
745 | } | |||
746 | break; | |||
747 | ||||
748 | case SID_STATUS_DOCPOS((26000 + 100) + 14): | |||
749 | { | |||
750 | OUString aStr = ScResId( STR_TABLE_COUNTreinterpret_cast<char const *>("STR_TABLE_COUNT" "\004" u8"Sheet %1 of %2") ); | |||
751 | ||||
752 | aStr = aStr.replaceFirst("%1", OUString::number( nTab + 1 ) ); | |||
753 | aStr = aStr.replaceFirst("%2", OUString::number( nTabCount ) ); | |||
754 | ||||
755 | rSet.Put( SfxStringItem( nWhich, aStr ) ); } | |||
756 | break; | |||
757 | ||||
758 | case SID_ROWCOL_SELCOUNT((26000 + 100) + 38): | |||
759 | { | |||
760 | ScRange aMarkRange; | |||
761 | GetViewData()->GetSimpleArea( aMarkRange ); | |||
762 | SCCOL nCol1, nCol2; | |||
763 | SCROW nRow1, nRow2; | |||
764 | nCol1 = aMarkRange.aStart.Col(); | |||
765 | nRow1 = aMarkRange.aStart.Row(); | |||
766 | nCol2 = aMarkRange.aEnd.Col(); | |||
767 | nRow2 = aMarkRange.aEnd.Row(); | |||
768 | if( nCol2 != nCol1 || nRow1 != nRow2 ) | |||
769 | { | |||
770 | const auto nRows = nRow2 - nRow1 + 1; | |||
771 | const auto nCols = nCol2 - nCol1 + 1; | |||
772 | const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetUILocaleDataWrapper(); | |||
773 | OUString aRowArg = ScResId(STR_SELCOUNT_ROWARGreinterpret_cast<char const *>("STR_SELCOUNT_ROWARG" "\004" u8"$1 row" "\004" u8"$1 rows"), nRows).replaceAll("$1", rLocaleData.getNum(nRows, 0)); | |||
774 | OUString aColArg = ScResId(STR_SELCOUNT_COLARGreinterpret_cast<char const *>("STR_SELCOUNT_COLARG" "\004" u8"$1 column" "\004" u8"$1 columns"), nCols).replaceAll("$1", rLocaleData.getNum(nCols, 0)); | |||
775 | OUString aStr = ScResId(STR_SELCOUNTreinterpret_cast<char const *>("STR_SELCOUNT" "\004" u8"Selected: $1, $2" )); | |||
776 | aStr = aStr.replaceAll("$1", aRowArg); | |||
777 | aStr = aStr.replaceAll("$2", aColArg); | |||
778 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
779 | } | |||
780 | else | |||
781 | { | |||
782 | SCSIZE nSelected, nTotal; | |||
783 | rDoc.GetFilterSelCount( nPosX, nPosY, nTab, nSelected, nTotal ); | |||
784 | if( nTotal ) | |||
785 | { | |||
786 | OUString aStr = ScResId( STR_FILTER_SELCOUNTreinterpret_cast<char const *>("STR_FILTER_SELCOUNT" "\004" u8"$1 of $2 records found") ); | |||
787 | aStr = aStr.replaceAll( "$1", OUString::number( nSelected ) ); | |||
788 | aStr = aStr.replaceAll( "$2", OUString::number( nTotal ) ); | |||
789 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
790 | } | |||
791 | } | |||
792 | } | |||
793 | break; | |||
794 | ||||
795 | // calculations etc. with date/time/Fail/position&size together | |||
796 | ||||
797 | // #i34458# The SfxStringItem belongs only into SID_TABLE_CELL. It no longer has to be | |||
798 | // duplicated in SID_ATTR_POSITION or SID_ATTR_SIZE for SvxPosSizeStatusBarControl. | |||
799 | case SID_TABLE_CELL( 10000 + 225 ): | |||
800 | { | |||
801 | // Test, if error under cursor | |||
802 | // (not rDoc.GetErrCode, to avoid erasing circular references) | |||
803 | ||||
804 | // In interpreter may happen via rescheduled Basic | |||
805 | if ( rDoc.IsInInterpreter() ) | |||
806 | rSet.Put( SfxStringItem( nWhich, "..." ) ); | |||
807 | else | |||
808 | { | |||
809 | FormulaError nErrCode = FormulaError::NONE; | |||
810 | ScFormulaCell* pCell = rDoc.GetFormulaCell(ScAddress(nPosX, nPosY, nTab)); | |||
811 | if (pCell && !pCell->IsRunning()) | |||
812 | nErrCode = pCell->GetErrCode(); | |||
813 | ||||
814 | OUString aFuncStr; | |||
815 | if ( pTabViewShell->GetFunction( aFuncStr, nErrCode ) ) | |||
816 | rSet.Put( SfxStringItem( nWhich, aFuncStr ) ); | |||
817 | } | |||
818 | } | |||
819 | break; | |||
820 | ||||
821 | case SID_DATA_SELECT((((26000 + 521) + 50))+39): | |||
822 | // HasSelectionData includes column content and validity, | |||
823 | // page fields have to be checked separately. | |||
824 | if ( !rDoc.HasSelectionData( nPosX, nPosY, nTab ) && | |||
825 | !pTabViewShell->HasPageFieldDataAtCursor() ) | |||
826 | rSet.DisableItem( nWhich ); | |||
827 | break; | |||
828 | ||||
829 | case FID_CURRENTVALIDATION((((26000 + 521) + 50))+51): | |||
830 | if ( !rDoc.HasValidationData( nPosX, nPosY, nTab )) | |||
831 | rSet.DisableItem( nWhich ); | |||
832 | break; | |||
833 | ||||
834 | case SID_STATUS_SUM((26000 + 100) + 30): | |||
835 | { | |||
836 | OUString aFuncStr; | |||
837 | if ( pTabViewShell->GetFunction( aFuncStr, FormulaError::NONE ) ) | |||
838 | rSet.Put( SfxStringItem( nWhich, aFuncStr ) ); | |||
839 | } | |||
840 | break; | |||
841 | ||||
842 | case FID_MERGE_ON((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 15): | |||
843 | if ( rDoc.GetChangeTrack() || !pTabViewShell->TestMergeCells() ) | |||
844 | rSet.DisableItem( nWhich ); | |||
845 | break; | |||
846 | ||||
847 | case FID_MERGE_OFF((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 16): | |||
848 | if ( rDoc.GetChangeTrack() || !pTabViewShell->TestRemoveMerge() ) | |||
849 | rSet.DisableItem( nWhich ); | |||
850 | break; | |||
851 | ||||
852 | case FID_MERGE_TOGGLE((((26000 + 521) + 50))+10): | |||
853 | if ( rDoc.GetChangeTrack() ) | |||
854 | rSet.DisableItem( nWhich ); | |||
855 | else | |||
856 | { | |||
857 | bool bCanMerge = pTabViewShell->TestMergeCells(); | |||
858 | bool bCanSplit = pTabViewShell->TestRemoveMerge(); | |||
859 | if( !bCanMerge && !bCanSplit ) | |||
860 | rSet.DisableItem( nWhich ); | |||
861 | else | |||
862 | rSet.Put( SfxBoolItem( nWhich, bCanSplit ) ); | |||
863 | } | |||
864 | break; | |||
865 | ||||
866 | case FID_INS_ROWBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 1): | |||
867 | if ( nPosY==0 || (rDoc.HasRowBreak(nPosY, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
868 | rSet.DisableItem( nWhich ); | |||
869 | break; | |||
870 | ||||
871 | case FID_INS_COLBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 2): | |||
872 | if ( nPosX==0 || (rDoc.HasColBreak(nPosX, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
873 | rSet.DisableItem( nWhich ); | |||
874 | break; | |||
875 | ||||
876 | case FID_DEL_ROWBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 3): | |||
877 | if ( nPosY==0 || !(rDoc.HasRowBreak(nPosY, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
878 | rSet.DisableItem( nWhich ); | |||
879 | break; | |||
880 | ||||
881 | case FID_DEL_COLBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 4): | |||
882 | if ( nPosX==0 || !(rDoc.HasColBreak(nPosX, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
883 | rSet.DisableItem( nWhich ); | |||
884 | break; | |||
885 | ||||
886 | case FID_FILL_TAB((((26000 + 200) + 20)) + 8): | |||
887 | if ( nTabSelCount < 2 ) | |||
888 | rSet.DisableItem( nWhich ); | |||
889 | break; | |||
890 | ||||
891 | case SID_INSERT_CURRENT_DATE((20000 +5000)+16): | |||
892 | case SID_INSERT_CURRENT_TIME((20000 +5000)+17): | |||
893 | { | |||
894 | if ( rDoc.IsTabProtected(nTab) && | |||
895 | rDoc.HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HasAttrFlags::Protected)) | |||
896 | rSet.DisableItem( nWhich ); | |||
897 | } | |||
898 | break; | |||
899 | ||||
900 | case SID_SELECT_SCENARIO((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+13): | |||
901 | { | |||
902 | std::vector<OUString> aList; | |||
903 | Color aDummyCol; | |||
904 | ||||
905 | if ( !rDoc.IsScenario(nTab) ) | |||
906 | { | |||
907 | OUString aStr; | |||
908 | ScScenarioFlags nFlags; | |||
909 | SCTAB nScTab = nTab + 1; | |||
910 | bool bSheetProtected = rDoc.IsTabProtected(nTab); | |||
911 | ||||
912 | while ( rDoc.IsScenario(nScTab) ) | |||
913 | { | |||
914 | rDoc.GetName( nScTab, aStr ); | |||
915 | aList.push_back(aStr); | |||
916 | rDoc.GetScenarioData( nScTab, aStr, aDummyCol, nFlags ); | |||
917 | aList.push_back(aStr); | |||
918 | // Protection is sal_True if both Sheet and Scenario are protected | |||
919 | aList.push_back((bSheetProtected && (nFlags & ScScenarioFlags::Protected)) ? OUString("1") : OUString("0")); | |||
920 | ++nScTab; | |||
921 | } | |||
922 | } | |||
923 | else | |||
924 | { | |||
925 | OUString aComment; | |||
926 | ScScenarioFlags nDummyFlags; | |||
927 | rDoc.GetScenarioData( nTab, aComment, aDummyCol, nDummyFlags ); | |||
928 | OSL_ENSURE( aList.empty(), "List not empty!" )do { if (true && (!(aList.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh.cxx" ":" "928" ": "), "%s", "List not empty!"); } } while (false); | |||
929 | aList.push_back(aComment); | |||
930 | } | |||
931 | ||||
932 | rSet.Put( SfxStringListItem( nWhich, &aList ) ); | |||
933 | } | |||
934 | break; | |||
935 | ||||
936 | case FID_ROW_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 3): | |||
937 | case FID_ROW_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 4): | |||
938 | case FID_COL_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 7): | |||
939 | case FID_COL_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 8): | |||
940 | case FID_COL_OPT_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 6): | |||
941 | case FID_ROW_OPT_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 2): | |||
942 | case FID_DELETE_CELL((((26000 + 200) + 20)) + 2): | |||
943 | if ( rDoc.IsTabProtected(nTab) || pDocSh->IsReadOnly()) | |||
| ||||
944 | rSet.DisableItem( nWhich ); | |||
945 | break; | |||
946 | ||||
947 | case SID_OUTLINE_MAKE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 27): | |||
948 | { | |||
949 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
950 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
951 | { | |||
952 | //! test for data pilot operation | |||
953 | } | |||
954 | else if (rDoc.GetChangeTrack()!=nullptr || GetViewData()->IsMultiMarked()) | |||
955 | { | |||
956 | rSet.DisableItem( nWhich ); | |||
957 | } | |||
958 | } | |||
959 | break; | |||
960 | case SID_OUTLINE_SHOW((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 26): | |||
961 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
962 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
963 | { | |||
964 | //! test for data pilot operation | |||
965 | } | |||
966 | else if (!pTabViewShell->OutlinePossible(false)) | |||
967 | rSet.DisableItem( nWhich ); | |||
968 | break; | |||
969 | ||||
970 | case SID_OUTLINE_HIDE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 25): | |||
971 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
972 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
973 | { | |||
974 | //! test for data pilot operation | |||
975 | } | |||
976 | else if (!pTabViewShell->OutlinePossible(true)) | |||
977 | rSet.DisableItem( nWhich ); | |||
978 | break; | |||
979 | ||||
980 | case SID_OUTLINE_REMOVE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 28): | |||
981 | { | |||
982 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
983 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
984 | { | |||
985 | //! test for data pilot operation | |||
986 | } | |||
987 | else | |||
988 | { | |||
989 | bool bCol, bRow; | |||
990 | pTabViewShell->TestRemoveOutline( bCol, bRow ); | |||
991 | if ( !bCol && !bRow ) | |||
992 | rSet.DisableItem( nWhich ); | |||
993 | } | |||
994 | } | |||
995 | break; | |||
996 | ||||
997 | case FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5): | |||
998 | { | |||
999 | SfxUInt16Item aWidthItem( FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5), rDoc.GetColWidth( nPosX , nTab) ); | |||
1000 | rSet.Put( aWidthItem ); | |||
1001 | if ( pDocSh->IsReadOnly()) | |||
1002 | rSet.DisableItem( nWhich ); | |||
1003 | ||||
1004 | //XXX disable if not conclusive | |||
1005 | } | |||
1006 | break; | |||
1007 | ||||
1008 | case FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1): | |||
1009 | { | |||
1010 | SfxUInt16Item aHeightItem( FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1), rDoc.GetRowHeight( nPosY , nTab) ); | |||
1011 | rSet.Put( aHeightItem ); | |||
1012 | //XXX disable if not conclusive | |||
1013 | if ( pDocSh->IsReadOnly()) | |||
1014 | rSet.DisableItem( nWhich ); | |||
1015 | } | |||
1016 | break; | |||
1017 | ||||
1018 | case SID_DETECTIVE_FILLMODE((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+6): | |||
1019 | rSet.Put(SfxBoolItem( nWhich, pTabViewShell->IsAuditShell() )); | |||
1020 | break; | |||
1021 | ||||
1022 | case FID_INPUTLINE_STATUS((26000 + 100)): | |||
1023 | OSL_FAIL( "Old update method. Use ScTabViewShell::UpdateInputHandler()." )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh.cxx" ":" "1023" ": "), "%s", "Old update method. Use ScTabViewShell::UpdateInputHandler()." ); } } while (false); | |||
1024 | break; | |||
1025 | ||||
1026 | case SID_SCENARIOS((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 12): // scenarios: | |||
1027 | if (!(rMark.IsMarked() || rMark.IsMultiMarked())) // only, if something selected | |||
1028 | rSet.DisableItem( nWhich ); | |||
1029 | break; | |||
1030 | ||||
1031 | case FID_NOTE_VISIBLE((((26000 + 521) + 50))+59): | |||
1032 | { | |||
1033 | const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab); | |||
1034 | if ( pNote && rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) ) | |||
1035 | rSet.Put( SfxBoolItem( nWhich, pNote->IsCaptionShown() ) ); | |||
1036 | else | |||
1037 | rSet.DisableItem( nWhich ); | |||
1038 | } | |||
1039 | break; | |||
1040 | ||||
1041 | case FID_HIDE_NOTE((((26000 + 521) + 50))+101): | |||
1042 | case FID_SHOW_NOTE((((26000 + 521) + 50))+100): | |||
1043 | { | |||
1044 | bool bEnable = false; | |||
1045 | bool bSearchForHidden = nWhich == FID_SHOW_NOTE((((26000 + 521) + 50))+100); | |||
1046 | if (!rMark.IsMarked() && !rMark.IsMultiMarked()) | |||
1047 | { | |||
1048 | // Check current cell | |||
1049 | const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab); | |||
1050 | if ( pNote && rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) ) | |||
1051 | if ( pNote->IsCaptionShown() != bSearchForHidden) | |||
1052 | bEnable = true; | |||
1053 | } | |||
1054 | else | |||
1055 | { | |||
1056 | // Check selection range | |||
1057 | ScRangeListRef aRangesRef; | |||
1058 | pData->GetMultiArea(aRangesRef); | |||
1059 | ScRangeList aRanges = *aRangesRef; | |||
1060 | std::vector<sc::NoteEntry> aNotes; | |||
1061 | rDoc.GetNotesInRange(aRanges, aNotes); | |||
1062 | for(const auto& rNote : aNotes) | |||
1063 | { | |||
1064 | const ScAddress& rAdr = rNote.maPos; | |||
1065 | if( rDoc.IsBlockEditable( rAdr.Tab(), rAdr.Col(), rAdr.Row(), rAdr.Col(), rAdr.Row() )) | |||
1066 | { | |||
1067 | if (rNote.mpNote->IsCaptionShown() != bSearchForHidden) | |||
1068 | { | |||
1069 | bEnable = true; | |||
1070 | break; | |||
1071 | } | |||
1072 | } | |||
1073 | } | |||
1074 | ||||
1075 | } | |||
1076 | if ( !bEnable ) | |||
1077 | rSet.DisableItem( nWhich ); | |||
1078 | } | |||
1079 | break; | |||
1080 | ||||
1081 | case FID_SHOW_ALL_NOTES((((26000 + 521) + 50))+102): | |||
1082 | case FID_HIDE_ALL_NOTES((((26000 + 521) + 50))+103): | |||
1083 | case FID_DELETE_ALL_NOTES((((26000 + 521) + 50))+104): | |||
1084 | { | |||
1085 | bool bHasNotes = false; | |||
1086 | ||||
1087 | for (auto const& rTab : rMark.GetSelectedTabs()) | |||
1088 | { | |||
1089 | if (rDoc.HasTabNotes( rTab )) | |||
1090 | { | |||
1091 | bHasNotes = true; | |||
1092 | break; | |||
1093 | } | |||
1094 | } | |||
1095 | ||||
1096 | if ( !bHasNotes ) | |||
1097 | rSet.DisableItem( nWhich ); | |||
1098 | } | |||
1099 | break; | |||
1100 | ||||
1101 | case SID_TOGGLE_NOTES( 10000 + 1098 ): | |||
1102 | { | |||
1103 | bool bHasNotes = false; | |||
1104 | ScRangeList aRanges; | |||
1105 | ||||
1106 | for (auto const& rTab : rMark.GetSelectedTabs()) | |||
1107 | { | |||
1108 | if (rDoc.HasTabNotes( rTab )) | |||
1109 | { | |||
1110 | bHasNotes = true; | |||
1111 | aRanges.push_back(ScRange(0,0,rTab,rDoc.MaxCol(),rDoc.MaxRow(),rTab)); | |||
1112 | } | |||
1113 | } | |||
1114 | ||||
1115 | if ( !bHasNotes ) | |||
1116 | rSet.DisableItem( nWhich ); | |||
1117 | else | |||
1118 | { | |||
1119 | CommentCaptionState eState = rDoc.GetAllNoteCaptionsState( aRanges ); | |||
1120 | bool bAllNotesInShown = (eState != ALLHIDDEN && eState != MIXED); | |||
1121 | rSet.Put( SfxBoolItem( SID_TOGGLE_NOTES( 10000 + 1098 ), bAllNotesInShown) ); | |||
1122 | } | |||
1123 | } | |||
1124 | break; | |||
1125 | ||||
1126 | case SID_DELETE_NOTE((((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+20))+2 ): | |||
1127 | { | |||
1128 | bool bEnable = false; | |||
1129 | if ( rMark.IsMarked() || rMark.IsMultiMarked() ) | |||
1130 | { | |||
1131 | if ( rDoc.IsSelectionEditable( rMark ) ) | |||
1132 | { | |||
1133 | // look for at least one note in selection | |||
1134 | ScRangeList aRanges; | |||
1135 | rMark.FillRangeListWithMarks( &aRanges, false ); | |||
1136 | bEnable = rDoc.ContainsNotesInRange( aRanges ); | |||
1137 | } | |||
1138 | } | |||
1139 | else | |||
1140 | { | |||
1141 | bEnable = rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) && | |||
1142 | rDoc.GetNote(nPosX, nPosY, nTab); | |||
1143 | } | |||
1144 | if ( !bEnable ) | |||
1145 | rSet.DisableItem( nWhich ); | |||
1146 | } | |||
1147 | break; | |||
1148 | ||||
1149 | case SID_OPENDLG_CONSOLIDATE((26000 + 100) + 50): | |||
1150 | case SCITEM_CONSOLIDATEDATA1105: | |||
1151 | { | |||
1152 | if (rDoc.GetChangeTrack()!=nullptr) | |||
1153 | rSet.DisableItem( nWhich); | |||
1154 | } | |||
1155 | break; | |||
1156 | ||||
1157 | case SID_CHINESE_CONVERSION( 10000 + 1016 ): | |||
1158 | case SID_HANGUL_HANJA_CONVERSION( 10000 + 959 ): | |||
1159 | ScViewUtil::HideDisabledSlot( rSet, pData->GetBindings(), nWhich ); | |||
1160 | break; | |||
1161 | ||||
1162 | case FID_USE_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 13): | |||
1163 | { | |||
1164 | if ( pDocSh && pDocSh->IsDocShared() ) | |||
1165 | rSet.DisableItem( nWhich ); | |||
1166 | else | |||
1167 | { | |||
1168 | ScRange aRange; | |||
1169 | if ( pData->GetSimpleArea( aRange ) != SC_MARK_SIMPLE ) | |||
1170 | rSet.DisableItem( nWhich ); | |||
1171 | } | |||
1172 | } | |||
1173 | break; | |||
1174 | ||||
1175 | case FID_DEFINE_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 11): | |||
1176 | case FID_INSERT_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 12): | |||
1177 | case FID_ADD_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 16): | |||
1178 | case SID_DEFINE_COLROWNAMERANGES((((26000 + 521) + 50))+58): | |||
1179 | { | |||
1180 | if ( pDocSh && pDocSh->IsDocShared() ) | |||
1181 | { | |||
1182 | rSet.DisableItem( nWhich ); | |||
1183 | } | |||
1184 | } | |||
1185 | break; | |||
1186 | ||||
1187 | case FID_DEFINE_CURRENT_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 24): | |||
1188 | { | |||
1189 | ScAddress aCurrentAddress( nPosX, nPosY, nTab ); | |||
1190 | ||||
1191 | if ( !rDoc.IsAddressInRangeName( RangeNameScope::GLOBAL, aCurrentAddress ) && | |||
1192 | !rDoc.IsAddressInRangeName( RangeNameScope::SHEET, aCurrentAddress )) | |||
1193 | { | |||
1194 | rSet.DisableItem( nWhich ); | |||
1195 | } | |||
1196 | } | |||
1197 | break; | |||
1198 | ||||
1199 | case SID_SPELL_DIALOG( 10000 + 243 ): | |||
1200 | { | |||
1201 | if ( pData && rDoc.IsTabProtected( pData->GetTabNo() ) ) | |||
1202 | { | |||
1203 | bool bVisible = false; | |||
1204 | SfxViewFrame* pViewFrame = ( pTabViewShell ? pTabViewShell->GetViewFrame() : nullptr ); | |||
1205 | if ( pViewFrame && pViewFrame->HasChildWindow( nWhich ) ) | |||
1206 | { | |||
1207 | SfxChildWindow* pChild = pViewFrame->GetChildWindow( nWhich ); | |||
1208 | std::shared_ptr<SfxDialogController> xController = pChild ? pChild->GetController() : nullptr; | |||
1209 | if (xController && xController->getDialog()->get_visible()) | |||
1210 | { | |||
1211 | bVisible = true; | |||
1212 | } | |||
1213 | } | |||
1214 | if ( !bVisible ) | |||
1215 | { | |||
1216 | rSet.DisableItem( nWhich ); | |||
1217 | } | |||
1218 | } | |||
1219 | } | |||
1220 | break; | |||
1221 | ||||
1222 | case SID_OPENDLG_CURRENTCONDFRMT((26000 + 100) + 58): | |||
1223 | case SID_OPENDLG_CURRENTCONDFRMT_MANAGER((26000 + 100) + 64): | |||
1224 | { | |||
1225 | const SfxPoolItem* pItem = rDoc.GetAttr( nPosX, nPosY, nTab, ATTR_CONDITIONAL ); | |||
1226 | const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); | |||
1227 | ||||
1228 | if ( pCondFormatItem->GetCondFormatData().empty() ) | |||
1229 | rSet.DisableItem( nWhich ); | |||
1230 | else if ( pCondFormatItem->GetCondFormatData().size() == 1 ) | |||
1231 | rSet.DisableItem( SID_OPENDLG_CURRENTCONDFRMT_MANAGER((26000 + 100) + 64) ); | |||
1232 | else if ( pCondFormatItem->GetCondFormatData().size() > 1 ) | |||
1233 | rSet.DisableItem( SID_OPENDLG_CURRENTCONDFRMT((26000 + 100) + 58) ); | |||
1234 | } | |||
1235 | break; | |||
1236 | ||||
1237 | } // switch ( nWitch ) | |||
1238 | nWhich = aIter.NextWhich(); | |||
1239 | } // while ( nWitch ) | |||
1240 | } | |||
1241 | ||||
1242 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |