xref: /trunk/main/sc/source/ui/view/cellsh.cxx (revision a206ee71)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //------------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svl/slstitm.hxx>
32cdf0e10cSrcweir #include <svl/stritem.hxx>
33cdf0e10cSrcweir #include <svl/whiter.hxx>
34cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
35cdf0e10cSrcweir #include <svtools/cliplistener.hxx>
36cdf0e10cSrcweir #include <svtools/insdlg.hxx>
37cdf0e10cSrcweir #include <sot/formats.hxx>
38cdf0e10cSrcweir #include <svx/hlnkitem.hxx>
39cdf0e10cSrcweir #include <sfx2/app.hxx>
40cdf0e10cSrcweir #include <sfx2/bindings.hxx>
41cdf0e10cSrcweir #include <sfx2/childwin.hxx>
42cdf0e10cSrcweir #include <sfx2/objface.hxx>
43cdf0e10cSrcweir #include <sfx2/request.hxx>
44cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
45f120fe41SAndre Fischer #include <sfx2/sidebar/EnumContext.hxx>
46cdf0e10cSrcweir #include <svx/clipfmtitem.hxx>
47f120fe41SAndre Fischer #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
48cdf0e10cSrcweir #include <editeng/langitem.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "cellsh.hxx"
51cdf0e10cSrcweir #include "sc.hrc"
52cdf0e10cSrcweir #include "docsh.hxx"
53cdf0e10cSrcweir #include "attrib.hxx"
54cdf0e10cSrcweir #include "scresid.hxx"
55cdf0e10cSrcweir #include "tabvwsh.hxx"
56cdf0e10cSrcweir #include "impex.hxx"
57cdf0e10cSrcweir #include "cell.hxx"
58cdf0e10cSrcweir #include "scmod.hxx"
59cdf0e10cSrcweir #include "globstr.hrc"
60cdf0e10cSrcweir #include "transobj.hxx"
61cdf0e10cSrcweir #include "drwtrans.hxx"
62cdf0e10cSrcweir #include "scabstdlg.hxx"
63cdf0e10cSrcweir #include "dociter.hxx"
64cdf0e10cSrcweir #include "postit.hxx"
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //------------------------------------------------------------------
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #define ScCellShell
69cdf0e10cSrcweir #define	CellMovement
70cdf0e10cSrcweir #include "scslots.hxx"
71cdf0e10cSrcweir 
72cdf0e10cSrcweir TYPEINIT1( ScCellShell, ScFormatShell );
73cdf0e10cSrcweir 
SFX_IMPL_INTERFACE(ScCellShell,ScFormatShell,ScResId (SCSTR_CELLSHELL))74cdf0e10cSrcweir SFX_IMPL_INTERFACE(ScCellShell, ScFormatShell , ScResId(SCSTR_CELLSHELL) )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD |
77cdf0e10cSrcweir 								SFX_VISIBILITY_SERVER,
78cdf0e10cSrcweir 								ScResId(RID_OBJECTBAR_FORMAT));
79cdf0e10cSrcweir 	SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_CELLS));
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
ScCellShell(ScViewData * pData)83cdf0e10cSrcweir ScCellShell::ScCellShell(ScViewData* pData) :
84cdf0e10cSrcweir 	ScFormatShell(pData),
85cdf0e10cSrcweir     pImpl( new CellShell_Impl() ),
86cdf0e10cSrcweir 	bPastePossible(sal_False)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	SetHelpId(HID_SCSHELL_CELLSH);
89cdf0e10cSrcweir 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Cell")));
90f120fe41SAndre Fischer     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Cell));
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
~ScCellShell()93cdf0e10cSrcweir ScCellShell::~ScCellShell()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     if ( pImpl->m_pClipEvtLstnr )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->AddRemoveListener( GetViewData()->GetActiveWin(), sal_False );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		//  #103849# The listener may just now be waiting for the SolarMutex and call the link
100cdf0e10cSrcweir 		//  afterwards, in spite of RemoveListener. So the link has to be reset, too.
101cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->ClearCallbackLink();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->release();
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     delete pImpl->m_pLinkedDlg;
107cdf0e10cSrcweir     delete pImpl->m_pRequest;
108cdf0e10cSrcweir     delete pImpl;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //------------------------------------------------------------------
112cdf0e10cSrcweir 
GetBlockState(SfxItemSet & rSet)113cdf0e10cSrcweir void ScCellShell::GetBlockState( SfxItemSet& rSet )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
116cdf0e10cSrcweir 	ScRange aMarkRange;
117cdf0e10cSrcweir     ScMarkType eMarkType = GetViewData()->GetSimpleArea( aMarkRange );
118cdf0e10cSrcweir 	sal_Bool bSimpleArea = (eMarkType == SC_MARK_SIMPLE);
119cdf0e10cSrcweir 	sal_Bool bOnlyNotBecauseOfMatrix;
120cdf0e10cSrcweir 	sal_Bool bEditable = pTabViewShell->SelectionEditable( &bOnlyNotBecauseOfMatrix );
121cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
122cdf0e10cSrcweir     ScDocShell* pDocShell = GetViewData()->GetDocShell();
123cdf0e10cSrcweir     ScMarkData& rMark = GetViewData()->GetMarkData();
124cdf0e10cSrcweir 	SCCOL nCol1, nCol2;
125cdf0e10cSrcweir 	SCROW nRow1, nRow2;
126cdf0e10cSrcweir 	nCol1 = aMarkRange.aStart.Col();
127cdf0e10cSrcweir 	nRow1 = aMarkRange.aStart.Row();
128cdf0e10cSrcweir 	nCol2 = aMarkRange.aEnd.Col();
129cdf0e10cSrcweir 	nRow2 = aMarkRange.aEnd.Row();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
132cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
133cdf0e10cSrcweir 	while ( nWhich )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		sal_Bool bDisable = sal_False;
136cdf0e10cSrcweir 		sal_Bool bNeedEdit = sal_True;		// muss Selektion editierbar sein?
137cdf0e10cSrcweir 		switch ( nWhich )
138cdf0e10cSrcweir 		{
139cdf0e10cSrcweir 			case FID_FILL_TO_BOTTOM:	// Fuellen oben/unten
140cdf0e10cSrcweir 			case FID_FILL_TO_TOP:		// mind. 2 Zeilen markiert?
141cdf0e10cSrcweir 				bDisable = (!bSimpleArea) || (nRow1 == nRow2);
142cdf0e10cSrcweir 				if ( !bDisable && bEditable )
143cdf0e10cSrcweir 				{	// Matrix nicht zerreissen
144cdf0e10cSrcweir 					if ( nWhich == FID_FILL_TO_BOTTOM )
145cdf0e10cSrcweir 						bDisable = pDoc->HasSelectedBlockMatrixFragment(
146cdf0e10cSrcweir 							nCol1, nRow1, nCol2, nRow1, rMark );	// erste Zeile
147cdf0e10cSrcweir 					else
148cdf0e10cSrcweir 						bDisable = pDoc->HasSelectedBlockMatrixFragment(
149cdf0e10cSrcweir 							nCol1, nRow2, nCol2, nRow2, rMark );	// letzte Zeile
150cdf0e10cSrcweir 				}
151cdf0e10cSrcweir 				break;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			case FID_FILL_TO_RIGHT:		// Fuellen links/rechts
154cdf0e10cSrcweir 			case FID_FILL_TO_LEFT:		// mind. 2 Spalten markiert?
155cdf0e10cSrcweir 				bDisable = (!bSimpleArea) || (nCol1 == nCol2);
156cdf0e10cSrcweir 				if ( !bDisable && bEditable )
157cdf0e10cSrcweir 				{	// Matrix nicht zerreissen
158cdf0e10cSrcweir 					if ( nWhich == FID_FILL_TO_RIGHT )
159cdf0e10cSrcweir 						bDisable = pDoc->HasSelectedBlockMatrixFragment(
160cdf0e10cSrcweir 							nCol1, nRow1, nCol1, nRow2, rMark );	// erste Spalte
161cdf0e10cSrcweir 					else
162cdf0e10cSrcweir 						bDisable = pDoc->HasSelectedBlockMatrixFragment(
163cdf0e10cSrcweir 							nCol2, nRow1, nCol2, nRow2, rMark );	// letzte Spalte
164cdf0e10cSrcweir 				}
165cdf0e10cSrcweir 				break;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 			case FID_FILL_SERIES:		// Block fuellen
168cdf0e10cSrcweir 			case SID_OPENDLG_TABOP:		// Mehrfachoperationen, mind. 2 Zellen markiert?
169cdf0e10cSrcweir 				if (pDoc->GetChangeTrack()!=NULL &&nWhich ==SID_OPENDLG_TABOP)
170cdf0e10cSrcweir 					bDisable = sal_True;
171cdf0e10cSrcweir 				else
172cdf0e10cSrcweir 					bDisable = (!bSimpleArea) || (nCol1 == nCol2 && nRow1 == nRow2);
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 				if ( !bDisable && bEditable && nWhich == FID_FILL_SERIES )
175cdf0e10cSrcweir 				{	// Matrix nicht zerreissen
176cdf0e10cSrcweir 					bDisable = pDoc->HasSelectedBlockMatrixFragment(
177cdf0e10cSrcweir 							nCol1, nRow1, nCol2, nRow1, rMark )	// erste Zeile
178cdf0e10cSrcweir 						||	pDoc->HasSelectedBlockMatrixFragment(
179cdf0e10cSrcweir 							nCol1, nRow2, nCol2, nRow2, rMark )	// letzte Zeile
180cdf0e10cSrcweir 						||	pDoc->HasSelectedBlockMatrixFragment(
181cdf0e10cSrcweir 							nCol1, nRow1, nCol1, nRow2, rMark )	// erste Spalte
182cdf0e10cSrcweir 						||	pDoc->HasSelectedBlockMatrixFragment(
183cdf0e10cSrcweir 							nCol2, nRow1, nCol2, nRow2, rMark );	// letzte Spalte
184cdf0e10cSrcweir 				}
185cdf0e10cSrcweir 				break;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 			case SID_CUT:				// Ausschneiden,
188cdf0e10cSrcweir 			case FID_INS_CELL:			// Zellen einfuegen, nur einf. Selektion
189cdf0e10cSrcweir 				bDisable = (!bSimpleArea);
190cdf0e10cSrcweir 				break;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir             case FID_INS_ROW:           // insert rows
193cdf0e10cSrcweir             case FID_INS_CELLSDOWN:
194cdf0e10cSrcweir                 bDisable = (!bSimpleArea) || GetViewData()->SimpleColMarked();
195cdf0e10cSrcweir                 break;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir             case FID_INS_COLUMN:        // insert columns
198cdf0e10cSrcweir             case FID_INS_CELLSRIGHT:
199cdf0e10cSrcweir                 bDisable = (!bSimpleArea) || GetViewData()->SimpleRowMarked();
200cdf0e10cSrcweir                 break;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 			case SID_COPY:						// Kopieren
203cdf0e10cSrcweir 				// nur wegen Matrix nicht editierbar? Matrix nicht zerreissen
204cdf0e10cSrcweir 				//! schlaegt nicht zu, wenn geschuetzt UND Matrix, aber damit
205cdf0e10cSrcweir 				//! muss man leben.. wird in Copy-Routine abgefangen, sonst
206cdf0e10cSrcweir 				//! muesste hier nochmal Aufwand getrieben werden
207cdf0e10cSrcweir 				if ( !(!bEditable && bOnlyNotBecauseOfMatrix) )
208cdf0e10cSrcweir 					bNeedEdit = sal_False;			// erlaubt, wenn geschuetzt/ReadOnly
209cdf0e10cSrcweir 				break;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			case SID_AUTOFORMAT:		// Autoformat, mind. 3x3 selektiert
212cdf0e10cSrcweir 				bDisable =    (!bSimpleArea)
213cdf0e10cSrcweir 						   || ((nCol2 - nCol1) < 2) || ((nRow2 - nRow1) < 2);
214cdf0e10cSrcweir 				break;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 			case SID_OPENDLG_CONDFRMT :
217cdf0e10cSrcweir                 {
218cdf0e10cSrcweir                     if ( !bEditable && bOnlyNotBecauseOfMatrix )
219cdf0e10cSrcweir                     {
220cdf0e10cSrcweir                         bNeedEdit = sal_False;
221cdf0e10cSrcweir                     }
222cdf0e10cSrcweir                     if ( pDocShell && pDocShell->IsDocShared() )
223cdf0e10cSrcweir                     {
224cdf0e10cSrcweir                         bDisable = sal_True;
225cdf0e10cSrcweir                     }
226cdf0e10cSrcweir                 }
227cdf0e10cSrcweir                 break;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 			case FID_CONDITIONAL_FORMAT :
230cdf0e10cSrcweir 			case SID_CELL_FORMAT_RESET :
231cdf0e10cSrcweir 			case FID_CELL_FORMAT :
232cdf0e10cSrcweir 			case SID_ENABLE_HYPHENATION :
233cdf0e10cSrcweir 				// nur wegen Matrix nicht editierbar? Attribute trotzdem ok
234cdf0e10cSrcweir 				if ( !bEditable && bOnlyNotBecauseOfMatrix )
235cdf0e10cSrcweir 					bNeedEdit = sal_False;
236cdf0e10cSrcweir 				break;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir             case FID_VALIDATION:
239cdf0e10cSrcweir                 {
240cdf0e10cSrcweir                     if ( pDocShell && pDocShell->IsDocShared() )
241cdf0e10cSrcweir                     {
242cdf0e10cSrcweir                         bDisable = sal_True;
243cdf0e10cSrcweir                     }
244cdf0e10cSrcweir                 }
245cdf0e10cSrcweir                 break;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 			case SID_TRANSLITERATE_HALFWIDTH:
248cdf0e10cSrcweir 			case SID_TRANSLITERATE_FULLWIDTH:
249cdf0e10cSrcweir 			case SID_TRANSLITERATE_HIRAGANA:
250cdf0e10cSrcweir 			case SID_TRANSLITERATE_KATAGANA:
251cdf0e10cSrcweir                 ScViewUtil::HideDisabledSlot( rSet, GetViewData()->GetBindings(), nWhich );
252cdf0e10cSrcweir             break;
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 		if (!bDisable && bNeedEdit && !bEditable)
255cdf0e10cSrcweir 			bDisable = sal_True;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 		if (bDisable)
258cdf0e10cSrcweir 			rSet.DisableItem(nWhich);
259cdf0e10cSrcweir 		else if (nWhich == SID_ENABLE_HYPHENATION)
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 			// toggle slots need a bool item
262cdf0e10cSrcweir 			rSet.Put( SfxBoolItem( nWhich, sal_False ) );
263cdf0e10cSrcweir 		}
264cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
265cdf0e10cSrcweir 	}
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir //	Funktionen, die je nach Cursorposition disabled sind
269cdf0e10cSrcweir //	Default:
270cdf0e10cSrcweir //		SID_INSERT_POSTIT, SID_CHARMAP, SID_OPENDLG_FUNCTION
271cdf0e10cSrcweir 
GetCellState(SfxItemSet & rSet)272cdf0e10cSrcweir void ScCellShell::GetCellState( SfxItemSet& rSet )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     ScDocShell* pDocShell = GetViewData()->GetDocShell();
275cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
276cdf0e10cSrcweir 	ScAddress aCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
277cdf0e10cSrcweir 						GetViewData()->GetTabNo() );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
280cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
281cdf0e10cSrcweir 	while ( nWhich )
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		sal_Bool bDisable = sal_False;
284cdf0e10cSrcweir 		sal_Bool bNeedEdit = sal_True;		// muss Cursorposition editierbar sein?
285cdf0e10cSrcweir 		switch ( nWhich )
286cdf0e10cSrcweir 		{
287cdf0e10cSrcweir             case SID_THESAURUS:
288cdf0e10cSrcweir 				{
289cdf0e10cSrcweir 					CellType eType = pDoc->GetCellType( aCursor );
290cdf0e10cSrcweir 					bDisable = ( eType != CELLTYPE_STRING && eType != CELLTYPE_EDIT);
291cdf0e10cSrcweir 					if (!bDisable)
292cdf0e10cSrcweir 					{
293cdf0e10cSrcweir 						//	test for available languages
294cdf0e10cSrcweir 						sal_uInt16 nLang = ScViewUtil::GetEffLanguage( pDoc, aCursor );
295cdf0e10cSrcweir 						bDisable = !ScModule::HasThesaurusLanguage( nLang );
296cdf0e10cSrcweir 					}
297cdf0e10cSrcweir 				}
298cdf0e10cSrcweir 				break;
299cdf0e10cSrcweir 			case SID_OPENDLG_FUNCTION:
300cdf0e10cSrcweir 				{
301cdf0e10cSrcweir 					ScMarkData aMarkData=GetViewData()->GetMarkData();
302cdf0e10cSrcweir 					aMarkData.MarkToSimple();
303cdf0e10cSrcweir 					ScRange aRange;
304cdf0e10cSrcweir 					aMarkData.GetMarkArea(aRange);
305cdf0e10cSrcweir 					if(aMarkData.IsMarked())
306cdf0e10cSrcweir 					{
307cdf0e10cSrcweir 						if (!pDoc->IsBlockEditable( aCursor.Tab(), aRange.aStart.Col(),aRange.aStart.Row(),
308cdf0e10cSrcweir 											aRange.aEnd.Col(),aRange.aEnd.Row() ))
309cdf0e10cSrcweir 						{
310cdf0e10cSrcweir 							bDisable = sal_True;
311cdf0e10cSrcweir 						}
312cdf0e10cSrcweir 						bNeedEdit=sal_False;
313cdf0e10cSrcweir 					}
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 				}
316cdf0e10cSrcweir 				break;
317cdf0e10cSrcweir             case SID_INSERT_POSTIT:
318cdf0e10cSrcweir                 {
319cdf0e10cSrcweir                     if ( pDocShell && pDocShell->IsDocShared() )
320cdf0e10cSrcweir                     {
321cdf0e10cSrcweir                         bDisable = sal_True;
322cdf0e10cSrcweir                     }
323cdf0e10cSrcweir                 }
324cdf0e10cSrcweir                 break;
325cdf0e10cSrcweir 		}
326cdf0e10cSrcweir 		if (!bDisable && bNeedEdit)
327cdf0e10cSrcweir 			if (!pDoc->IsBlockEditable( aCursor.Tab(), aCursor.Col(),aCursor.Row(),
328cdf0e10cSrcweir 										aCursor.Col(),aCursor.Row() ))
329cdf0e10cSrcweir 				bDisable = sal_True;
330cdf0e10cSrcweir 		if (bDisable)
331cdf0e10cSrcweir 			rSet.DisableItem(nWhich);
332cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
lcl_TestFormat(SvxClipboardFmtItem & rFormats,const TransferableDataHelper & rDataHelper,SotFormatStringId nFormatId)336cdf0e10cSrcweir sal_Bool lcl_TestFormat( SvxClipboardFmtItem& rFormats, const TransferableDataHelper& rDataHelper,
337cdf0e10cSrcweir 						SotFormatStringId nFormatId )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	if ( rDataHelper.HasFormat( nFormatId ) )
340cdf0e10cSrcweir 	{
341cdf0e10cSrcweir 		//	#90675# translated format name strings are no longer inserted here,
342cdf0e10cSrcweir 		//	handled by "paste special" dialog / toolbox controller instead.
343cdf0e10cSrcweir 		//	Only the object type name has to be set here:
344cdf0e10cSrcweir 		String aStrVal;
345cdf0e10cSrcweir 		if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE )
346cdf0e10cSrcweir 		{
347cdf0e10cSrcweir 			TransferableObjectDescriptor aDesc;
348cdf0e10cSrcweir 			if ( ((TransferableDataHelper&)rDataHelper).GetTransferableObjectDescriptor(
349cdf0e10cSrcweir 										SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc ) )
350cdf0e10cSrcweir 				aStrVal = aDesc.maTypeName;
351cdf0e10cSrcweir 		}
352cdf0e10cSrcweir 		else if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE
353cdf0e10cSrcweir 		  || nFormatId == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
354cdf0e10cSrcweir 		{
355cdf0e10cSrcweir 			String aSource;
356cdf0e10cSrcweir             SvPasteObjectHelper::GetEmbeddedName( rDataHelper, aStrVal, aSource, nFormatId );
357cdf0e10cSrcweir 		}
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 		if ( aStrVal.Len() )
360cdf0e10cSrcweir 			rFormats.AddClipbrdFormat( nFormatId, aStrVal );
361cdf0e10cSrcweir 		else
362cdf0e10cSrcweir 			rFormats.AddClipbrdFormat( nFormatId );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 		return sal_True;
365cdf0e10cSrcweir 	}
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 	return sal_False;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
GetPossibleClipboardFormats(SvxClipboardFmtItem & rFormats)370cdf0e10cSrcweir void ScCellShell::GetPossibleClipboardFormats( SvxClipboardFmtItem& rFormats )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	Window* pWin = GetViewData()->GetActiveWin();
373cdf0e10cSrcweir 	sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_DRAWING );
378cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_SVXB );
379cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_GDIMETAFILE );
380*a206ee71SArmin Le Grand 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_PNG );
381cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_BITMAP );
382cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBED_SOURCE );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	if ( !bDraw )
385cdf0e10cSrcweir 	{
386cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_LINK );
387cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_STRING );
388cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_DIF );
389cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_RTF );
390cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_HTML );
391cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_HTML_SIMPLE );
392cdf0e10cSrcweir         lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_BIFF_8 );
393cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_BIFF_5 );
394cdf0e10cSrcweir 	}
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	if ( !lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) )
397cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE );
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir //	Einfuegen, Inhalte einfuegen
401cdf0e10cSrcweir 
lcl_IsCellPastePossible(const TransferableDataHelper & rData)402cdf0e10cSrcweir sal_Bool lcl_IsCellPastePossible( const TransferableDataHelper& rData )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir 	sal_Bool bPossible = sal_False;
405cdf0e10cSrcweir 	if ( ScTransferObj::GetOwnClipboard( NULL ) || ScDrawTransferObj::GetOwnClipboard( NULL ) )
406cdf0e10cSrcweir 		bPossible = sal_True;
407cdf0e10cSrcweir 	else
408cdf0e10cSrcweir 	{
409*a206ee71SArmin Le Grand 		if ( rData.HasFormat( SOT_FORMATSTR_ID_PNG ) ||
410*a206ee71SArmin Le Grand              rData.HasFormat( SOT_FORMAT_BITMAP ) ||
411cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_GDIMETAFILE ) ||
412cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_SVXB ) ||
413cdf0e10cSrcweir 			 rData.HasFormat( FORMAT_PRIVATE ) ||
414cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_RTF ) ||
415cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) ||
416cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ) ||
417cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) ||
418cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) ||
419cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) ||
420cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_STRING ) ||
421cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) ||
422cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK ) ||
423cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_HTML ) ||
424cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_HTML_SIMPLE ) ||
425cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_DIF ) )
426cdf0e10cSrcweir 		{
427cdf0e10cSrcweir 			bPossible = sal_True;
428cdf0e10cSrcweir 		}
429cdf0e10cSrcweir 	}
430cdf0e10cSrcweir 	return bPossible;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
IMPL_LINK(ScCellShell,ClipboardChanged,TransferableDataHelper *,pDataHelper)433cdf0e10cSrcweir IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir 	if ( pDataHelper )
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		bPastePossible = lcl_IsCellPastePossible( *pDataHelper );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 		SfxBindings& rBindings = GetViewData()->GetBindings();
440cdf0e10cSrcweir 		rBindings.Invalidate( SID_PASTE );
441cdf0e10cSrcweir         rBindings.Invalidate( SID_PASTE_SPECIAL );
442cdf0e10cSrcweir 		rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 	return 0;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
GetClipState(SfxItemSet & rSet)448cdf0e10cSrcweir void __EXPORT ScCellShell::GetClipState( SfxItemSet& rSet )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir // SID_PASTE
451cdf0e10cSrcweir // SID_PASTE_SPECIAL
452cdf0e10cSrcweir // SID_CLIPBOARD_FORMAT_ITEMS
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     if ( !pImpl->m_pClipEvtLstnr )
455cdf0e10cSrcweir 	{
456cdf0e10cSrcweir 		// create listener
457cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScCellShell, ClipboardChanged ) );
458cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->acquire();
459cdf0e10cSrcweir 		Window* pWin = GetViewData()->GetActiveWin();
460cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->AddRemoveListener( pWin, sal_True );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 		// get initial state
463cdf0e10cSrcweir 		TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
464cdf0e10cSrcweir 		bPastePossible = lcl_IsCellPastePossible( aDataHelper );
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	sal_Bool bDisable = !bPastePossible;
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	//	Zellschutz / Multiselektion
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	if (!bDisable)
472cdf0e10cSrcweir 	{
473cdf0e10cSrcweir 		SCCOL nCol = GetViewData()->GetCurX();
474cdf0e10cSrcweir 		SCROW nRow = GetViewData()->GetCurY();
475cdf0e10cSrcweir 		SCTAB nTab = GetViewData()->GetTabNo();
476cdf0e10cSrcweir 		ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
477cdf0e10cSrcweir 		if (!pDoc->IsBlockEditable( nTab, nCol,nRow, nCol,nRow ))
478cdf0e10cSrcweir 			bDisable = sal_True;
479cdf0e10cSrcweir         ScRange aDummy;
480cdf0e10cSrcweir         ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
481cdf0e10cSrcweir         if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
482cdf0e10cSrcweir 			bDisable = sal_True;
483cdf0e10cSrcweir 	}
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	if (bDisable)
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		rSet.DisableItem( SID_PASTE );
488cdf0e10cSrcweir         rSet.DisableItem( SID_PASTE_SPECIAL );
489cdf0e10cSrcweir 		rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS );
490cdf0e10cSrcweir 	}
491cdf0e10cSrcweir 	else if ( rSet.GetItemState( SID_CLIPBOARD_FORMAT_ITEMS ) != SFX_ITEM_UNKNOWN )
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir 		SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
494cdf0e10cSrcweir 		GetPossibleClipboardFormats( aFormats );
495cdf0e10cSrcweir 		rSet.Put( aFormats );
496cdf0e10cSrcweir 	}
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir //	only SID_HYPERLINK_GETLINK:
500cdf0e10cSrcweir 
GetHLinkState(SfxItemSet & rSet)501cdf0e10cSrcweir void ScCellShell::GetHLinkState( SfxItemSet& rSet )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir 	//	always return an item (or inserting will be disabled)
504cdf0e10cSrcweir 	//	if the cell at the cursor contains only a link, return that link
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 	SvxHyperlinkItem aHLinkItem;
507cdf0e10cSrcweir 	if ( !GetViewData()->GetView()->HasBookmarkAtCursor( &aHLinkItem ) )
508cdf0e10cSrcweir 	{
509cdf0e10cSrcweir 		//!	put selected text into item?
510cdf0e10cSrcweir 	}
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 	rSet.Put(aHLinkItem);
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
GetState(SfxItemSet & rSet)515cdf0e10cSrcweir void ScCellShell::GetState(SfxItemSet &rSet)
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	// removed: SID_BORDER_OBJECT (old Basic)
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
520cdf0e10cSrcweir //     sal_Bool bOle = pTabViewShell->GetViewFrame()->GetFrame().IsInPlace();
521cdf0e10cSrcweir // 	sal_Bool bTabProt = GetViewData()->GetDocument()->IsTabProtected(GetViewData()->GetTabNo());
522cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
523cdf0e10cSrcweir     ScViewData* pData       = GetViewData();
524cdf0e10cSrcweir 	ScDocument* pDoc		= pData->GetDocument();
525cdf0e10cSrcweir 	ScMarkData& rMark		= pData->GetMarkData();
526cdf0e10cSrcweir 	SCCOL		nPosX		= pData->GetCurX();
527cdf0e10cSrcweir 	SCROW		nPosY		= pData->GetCurY();
528cdf0e10cSrcweir 	SCTAB		nTab		= pData->GetTabNo();
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
531cdf0e10cSrcweir 	SCTAB nTabSelCount = rMark.GetSelectCount();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
536cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
537cdf0e10cSrcweir 	while ( nWhich )
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir 		switch ( nWhich )
540cdf0e10cSrcweir 		{
541cdf0e10cSrcweir 			case SID_DETECTIVE_REFRESH:
542cdf0e10cSrcweir 				if (!pDoc->HasDetectiveOperations())
543cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
544cdf0e10cSrcweir 				break;
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 			case SID_RANGE_ADDRESS:
547cdf0e10cSrcweir 				{
548cdf0e10cSrcweir 					ScRange aRange;
549cdf0e10cSrcweir 					if ( pData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
550cdf0e10cSrcweir 					{
551cdf0e10cSrcweir 						String aStr;
552cdf0e10cSrcweir 						sal_uInt16 nFlags = SCA_VALID | SCA_TAB_3D;
553cdf0e10cSrcweir 						aRange.Format(aStr,nFlags,pDoc);
554cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich, aStr ) );
555cdf0e10cSrcweir 					}
556cdf0e10cSrcweir 				}
557cdf0e10cSrcweir 				break;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 			case SID_RANGE_NOTETEXT:
560cdf0e10cSrcweir 				{
561cdf0e10cSrcweir 					//	#43343# always take cursor position, do not use top-left cell of selection
562cdf0e10cSrcweir 					ScAddress aPos( nPosX, nPosY, nTab );
563cdf0e10cSrcweir 					String aNoteText;
564cdf0e10cSrcweir 					if ( const ScPostIt* pNote = pDoc->GetNote( aPos ) )
565cdf0e10cSrcweir                         aNoteText = pNote->GetText();
566cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aNoteText ) );
567cdf0e10cSrcweir 				}
568cdf0e10cSrcweir 				break;
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 			case SID_RANGE_ROW:
571cdf0e10cSrcweir 				rSet.Put( SfxInt32Item( nWhich, nPosY+1 ) );
572cdf0e10cSrcweir 				break;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 			case SID_RANGE_COL:
575cdf0e10cSrcweir 				rSet.Put( SfxInt16Item( nWhich, nPosX+1 ) );
576cdf0e10cSrcweir 				break;
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 			case SID_RANGE_TABLE:
579cdf0e10cSrcweir 				rSet.Put( SfxInt16Item( nWhich, nTab+1 ) );
580cdf0e10cSrcweir 				break;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 			case SID_RANGE_VALUE:
583cdf0e10cSrcweir 				{
584cdf0e10cSrcweir 					double nValue;
585cdf0e10cSrcweir 					pDoc->GetValue( nPosX, nPosY, nTab, nValue );
586cdf0e10cSrcweir 					rSet.Put( ScDoubleItem( nWhich, nValue ) );
587cdf0e10cSrcweir 				}
588cdf0e10cSrcweir 				break;
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 			case SID_RANGE_FORMULA:
591cdf0e10cSrcweir 				{
592cdf0e10cSrcweir 					String aString;
593cdf0e10cSrcweir 					pDoc->GetFormula( nPosX, nPosY, nTab, aString );
594cdf0e10cSrcweir 					if( aString.Len() == 0 )
595cdf0e10cSrcweir 					{
596cdf0e10cSrcweir 						pDoc->GetInputString( nPosX, nPosY, nTab, aString );
597cdf0e10cSrcweir 					}
598cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aString ) );
599cdf0e10cSrcweir 				}
600cdf0e10cSrcweir 				break;
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 			case SID_RANGE_TEXTVALUE:
603cdf0e10cSrcweir 				{
604cdf0e10cSrcweir 					String aString;
605cdf0e10cSrcweir 					pDoc->GetString( nPosX, nPosY, nTab, aString );
606cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aString ) );
607cdf0e10cSrcweir 				}
608cdf0e10cSrcweir 				break;
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 			case SID_STATUS_SELMODE:
611cdf0e10cSrcweir 				{
612cdf0e10cSrcweir 					/* 0: STD	Click hebt Sel auf
613cdf0e10cSrcweir 					 * 1: ER	Click erweitert Selektion
614cdf0e10cSrcweir 					 * 2: ERG	Click definiert weitere Selektion
615cdf0e10cSrcweir 					 */
616cdf0e10cSrcweir 					sal_uInt16 nMode = pTabViewShell->GetLockedModifiers();
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 					switch ( nMode )
619cdf0e10cSrcweir 					{
620cdf0e10cSrcweir 						case KEY_SHIFT: nMode = 1;	break;
621cdf0e10cSrcweir 						case KEY_MOD1:	nMode = 2;	break; // Control-Taste
622cdf0e10cSrcweir 						case 0:
623cdf0e10cSrcweir 						default:
624cdf0e10cSrcweir 							nMode = 0;
625cdf0e10cSrcweir 					}
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 					rSet.Put( SfxUInt16Item( nWhich, nMode ) );
628cdf0e10cSrcweir 				}
629cdf0e10cSrcweir 				break;
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 			case SID_STATUS_DOCPOS:
632cdf0e10cSrcweir 				{
633cdf0e10cSrcweir 					String	aStr( ScGlobal::GetRscString( STR_TABLE ) );
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 					aStr += ' ';
636cdf0e10cSrcweir 					aStr += String::CreateFromInt32( nTab + 1 );
637cdf0e10cSrcweir 					aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
638cdf0e10cSrcweir 					aStr += String::CreateFromInt32( nTabCount );
639cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aStr ) );
640cdf0e10cSrcweir 				}
641cdf0e10cSrcweir 				break;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 			//	Summe etc. mit Datum/Zeit/Fehler/Pos&Groesse zusammengefasst
644cdf0e10cSrcweir 
645cdf0e10cSrcweir             // #i34458# The SfxStringItem belongs only into SID_TABLE_CELL. It no longer has to be
646cdf0e10cSrcweir             // duplicated in SID_ATTR_POSITION or SID_ATTR_SIZE for SvxPosSizeStatusBarControl.
647cdf0e10cSrcweir 			case SID_TABLE_CELL:
648cdf0e10cSrcweir 				{
649cdf0e10cSrcweir 					//	Testen, ob Fehler unter Cursor
650cdf0e10cSrcweir 					//	(nicht pDoc->GetErrCode, um keine zirkulaeren Referenzen auszuloesen)
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 					// In interpreter may happen via rescheduled Basic
653cdf0e10cSrcweir 					if ( pDoc->IsInInterpreter() )
654cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich,
655cdf0e10cSrcweir 							String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("...")) ) );
656cdf0e10cSrcweir 					else
657cdf0e10cSrcweir 					{
658cdf0e10cSrcweir 						sal_uInt16 nErrCode = 0;
659cdf0e10cSrcweir 						ScBaseCell* pCell;
660cdf0e10cSrcweir 						pDoc->GetCell( nPosX, nPosY, nTab, pCell );
661cdf0e10cSrcweir 						if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
662cdf0e10cSrcweir 						{
663cdf0e10cSrcweir 							ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
664cdf0e10cSrcweir 							if (!pFCell->IsRunning())
665cdf0e10cSrcweir 								nErrCode = pFCell->GetErrCode();
666cdf0e10cSrcweir 						}
667cdf0e10cSrcweir 
668cdf0e10cSrcweir                         String aFuncStr;
669cdf0e10cSrcweir                         if ( pTabViewShell->GetFunction( aFuncStr, nErrCode ) )
670cdf0e10cSrcweir                             rSet.Put( SfxStringItem( nWhich, aFuncStr ) );
671cdf0e10cSrcweir 					}
672cdf0e10cSrcweir 				}
673cdf0e10cSrcweir 				break;
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 			case SID_DATA_SELECT:
676cdf0e10cSrcweir                 // HasSelectionData includes column content and validity,
677cdf0e10cSrcweir                 // page fields have to be checked separately.
678cdf0e10cSrcweir                 if ( !pDoc->HasSelectionData( nPosX, nPosY, nTab ) &&
679cdf0e10cSrcweir                      !pTabViewShell->HasPageFieldDataAtCursor() )
680cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
681cdf0e10cSrcweir 				break;
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 			case SID_STATUS_SUM:
684cdf0e10cSrcweir 				{
685cdf0e10cSrcweir 					String aFuncStr;
686cdf0e10cSrcweir 					if ( pTabViewShell->GetFunction( aFuncStr ) )
687cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich, aFuncStr ) );
688cdf0e10cSrcweir 				}
689cdf0e10cSrcweir 				break;
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 			case FID_MERGE_ON:
692cdf0e10cSrcweir 				if ( pDoc->GetChangeTrack() || !pTabViewShell->TestMergeCells() )
693cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
694cdf0e10cSrcweir 				break;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 			case FID_MERGE_OFF:
697cdf0e10cSrcweir 				if ( pDoc->GetChangeTrack() || !pTabViewShell->TestRemoveMerge() )
698cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
699cdf0e10cSrcweir 				break;
700cdf0e10cSrcweir 
701cdf0e10cSrcweir             case FID_MERGE_TOGGLE:
702cdf0e10cSrcweir                 if ( pDoc->GetChangeTrack() )
703cdf0e10cSrcweir                     rSet.DisableItem( nWhich );
704cdf0e10cSrcweir                 else
705cdf0e10cSrcweir                 {
706cdf0e10cSrcweir                     bool bCanMerge = pTabViewShell->TestMergeCells();
707cdf0e10cSrcweir                     bool bCanSplit = pTabViewShell->TestRemoveMerge();
708cdf0e10cSrcweir                     if( !bCanMerge && !bCanSplit )
709cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
710cdf0e10cSrcweir                     else
711cdf0e10cSrcweir                         rSet.Put( SfxBoolItem( nWhich, bCanSplit ) );
712cdf0e10cSrcweir                 }
713cdf0e10cSrcweir                 break;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 			case FID_INS_ROWBRK:
716cdf0e10cSrcweir                 if ( nPosY==0 || (pDoc->HasRowBreak(nPosY, nTab) & BREAK_MANUAL) )
717cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
718cdf0e10cSrcweir 				break;
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 			case FID_INS_COLBRK:
721cdf0e10cSrcweir                 if ( nPosX==0 || (pDoc->HasColBreak(nPosX, nTab) & BREAK_MANUAL) )
722cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
723cdf0e10cSrcweir 				break;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 			case FID_DEL_ROWBRK:
726cdf0e10cSrcweir                 if ( nPosY==0 || (pDoc->HasRowBreak(nPosY, nTab) & BREAK_MANUAL) == 0 )
727cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
728cdf0e10cSrcweir 				break;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 			case FID_DEL_COLBRK:
731cdf0e10cSrcweir                 if ( nPosX==0 || (pDoc->HasColBreak(nPosX, nTab) & BREAK_MANUAL) == 0 )
732cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
733cdf0e10cSrcweir 				break;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 			case FID_FILL_TAB:
736cdf0e10cSrcweir 				if ( nTabSelCount < 2 )
737cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
738cdf0e10cSrcweir 				break;
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 			case SID_SELECT_SCENARIO:
741cdf0e10cSrcweir 				{
742cdf0e10cSrcweir                     // ScDocument* pDoc = GetViewData()->GetDocument();
743cdf0e10cSrcweir                     // SCTAB       nTab = GetViewData()->GetTabNo();
744cdf0e10cSrcweir 					List		aList;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 					Color	aDummyCol;
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 					if ( !pDoc->IsScenario(nTab) )
749cdf0e10cSrcweir 					{
750cdf0e10cSrcweir 						String aStr;
751cdf0e10cSrcweir 						sal_uInt16 nFlags;
752cdf0e10cSrcweir 						SCTAB nScTab = nTab + 1;
753cdf0e10cSrcweir 						String aProtect;
754cdf0e10cSrcweir 						bool bSheetProtected = pDoc->IsTabProtected(nTab);
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 						while ( pDoc->IsScenario(nScTab) )
757cdf0e10cSrcweir 						{
758cdf0e10cSrcweir 							pDoc->GetName( nScTab, aStr );
759cdf0e10cSrcweir 							aList.Insert( new String( aStr ), LIST_APPEND );
760cdf0e10cSrcweir 							pDoc->GetScenarioData( nScTab, aStr, aDummyCol, nFlags );
761cdf0e10cSrcweir 							aList.Insert( new String( aStr ), LIST_APPEND );
762cdf0e10cSrcweir 							// Protection is sal_True if both Sheet and Scenario are protected
763cdf0e10cSrcweir 							aProtect = (bSheetProtected && (nFlags & SC_SCENARIO_PROTECT)) ? '1' : '0';
764cdf0e10cSrcweir 							aList.Insert( new String( aProtect), LIST_APPEND );
765cdf0e10cSrcweir 							++nScTab;
766cdf0e10cSrcweir 						}
767cdf0e10cSrcweir 					}
768cdf0e10cSrcweir 					else
769cdf0e10cSrcweir 					{
770cdf0e10cSrcweir 						String	aComment;
771cdf0e10cSrcweir 						sal_uInt16	nDummyFlags;
772cdf0e10cSrcweir 						pDoc->GetScenarioData( nTab, aComment, aDummyCol, nDummyFlags );
773cdf0e10cSrcweir 						DBG_ASSERT( aList.Count() == 0, "List not empty!" );
774cdf0e10cSrcweir 						aList.Insert( new String( aComment ) );
775cdf0e10cSrcweir 					}
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 					rSet.Put( SfxStringListItem( nWhich, &aList ) );
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 					sal_uLong nCount = aList.Count();
780cdf0e10cSrcweir 					for ( sal_uLong i=0; i<nCount; i++ )
781cdf0e10cSrcweir 						delete (String*) aList.GetObject(i);
782cdf0e10cSrcweir 				}
783cdf0e10cSrcweir 				break;
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 			case FID_ROW_HIDE:
786cdf0e10cSrcweir 			case FID_ROW_SHOW:
787cdf0e10cSrcweir 			case FID_COL_HIDE:
788cdf0e10cSrcweir 			case FID_COL_SHOW:
789cdf0e10cSrcweir 			case FID_COL_OPT_WIDTH:
790cdf0e10cSrcweir 			case FID_ROW_OPT_HEIGHT:
791cdf0e10cSrcweir 			case FID_DELETE_CELL:
792cdf0e10cSrcweir 				if ( pDoc->IsTabProtected(nTab) || pDocSh->IsReadOnly())
793cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
794cdf0e10cSrcweir 				break;
795cdf0e10cSrcweir 
796cdf0e10cSrcweir /*	Zellschutz bei selektierten Zellen wird bei anderen Funktionen auch nicht abgefragt...
797cdf0e10cSrcweir 			case SID_DELETE:
798cdf0e10cSrcweir 				{
799cdf0e10cSrcweir 					if ( pDoc->IsTabProtected(nTab) )
800cdf0e10cSrcweir 					{
801cdf0e10cSrcweir 						const SfxItemSet&		rAttrSet  = GetSelectionPattern()->GetItemSet();
802cdf0e10cSrcweir 						const ScProtectionAttr& rProtAttr = (const ScProtectionAttr&)rAttrSet.Get( ATTR_PROTECTION, sal_True );
803cdf0e10cSrcweir 						if ( rProtAttr.GetProtection() )
804cdf0e10cSrcweir 							rSet.DisableItem( nWhich );
805cdf0e10cSrcweir 					}
806cdf0e10cSrcweir 				}
807cdf0e10cSrcweir 				break;
808cdf0e10cSrcweir */
809cdf0e10cSrcweir 			case SID_OUTLINE_MAKE:
810cdf0e10cSrcweir 				{
811cdf0e10cSrcweir     				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
812cdf0e10cSrcweir                 							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
813cdf0e10cSrcweir                     {
814cdf0e10cSrcweir                         //! test for data pilot operation
815cdf0e10cSrcweir                     }
816cdf0e10cSrcweir 					else if (pDoc->GetChangeTrack()!=NULL || GetViewData()->IsMultiMarked())
817cdf0e10cSrcweir 					{
818cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
819cdf0e10cSrcweir 					}
820cdf0e10cSrcweir 				}
821cdf0e10cSrcweir 				break;
822cdf0e10cSrcweir 			case SID_OUTLINE_SHOW:
823cdf0e10cSrcweir 				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
824cdf0e10cSrcweir             							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
825cdf0e10cSrcweir                 {
826cdf0e10cSrcweir                     //! test for data pilot operation
827cdf0e10cSrcweir                 }
828cdf0e10cSrcweir 				else if (!pTabViewShell->OutlinePossible(sal_False))
829cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
830cdf0e10cSrcweir 				break;
831cdf0e10cSrcweir 
832cdf0e10cSrcweir 			case SID_OUTLINE_HIDE:
833cdf0e10cSrcweir 				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
834cdf0e10cSrcweir             							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
835cdf0e10cSrcweir                 {
836cdf0e10cSrcweir                     //! test for data pilot operation
837cdf0e10cSrcweir                 }
838cdf0e10cSrcweir 				else if (!pTabViewShell->OutlinePossible(sal_True))
839cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
840cdf0e10cSrcweir 				break;
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 			case SID_OUTLINE_REMOVE:
843cdf0e10cSrcweir 				{
844cdf0e10cSrcweir     				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
845cdf0e10cSrcweir                 							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
846cdf0e10cSrcweir                     {
847cdf0e10cSrcweir                         //! test for data pilot operation
848cdf0e10cSrcweir                     }
849cdf0e10cSrcweir                     else
850cdf0e10cSrcweir                     {
851cdf0e10cSrcweir     					sal_Bool bCol, bRow;
852cdf0e10cSrcweir     					pTabViewShell->TestRemoveOutline( bCol, bRow );
853cdf0e10cSrcweir     					if ( !bCol && !bRow )
854cdf0e10cSrcweir     						rSet.DisableItem( nWhich );
855cdf0e10cSrcweir                     }
856cdf0e10cSrcweir 				}
857cdf0e10cSrcweir 				break;
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 			case FID_COL_WIDTH:
860cdf0e10cSrcweir 				{
861cdf0e10cSrcweir 					//GetViewData()->GetCurX();
862cdf0e10cSrcweir 					SfxUInt16Item aWidthItem( FID_COL_WIDTH, pDoc->GetColWidth( nPosX , nTab) );
863cdf0e10cSrcweir 					rSet.Put( aWidthItem );
864cdf0e10cSrcweir 					if ( pDocSh->IsReadOnly())
865cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 					//XXX Disablen wenn nicht eindeutig
868cdf0e10cSrcweir 				}
869cdf0e10cSrcweir 				break;
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 			case FID_ROW_HEIGHT:
872cdf0e10cSrcweir 				{
873cdf0e10cSrcweir 					//GetViewData()->GetCurY();
874cdf0e10cSrcweir 					SfxUInt16Item aHeightItem( FID_ROW_HEIGHT, pDoc->GetRowHeight( nPosY , nTab) );
875cdf0e10cSrcweir 					rSet.Put( aHeightItem );
876cdf0e10cSrcweir 					//XXX Disablen wenn nicht eindeutig
877cdf0e10cSrcweir 					if ( pDocSh->IsReadOnly())
878cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
879cdf0e10cSrcweir 				}
880cdf0e10cSrcweir 				break;
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 			case SID_DETECTIVE_FILLMODE:
883cdf0e10cSrcweir 				rSet.Put(SfxBoolItem( nWhich, pTabViewShell->IsAuditShell() ));
884cdf0e10cSrcweir 				break;
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 			case FID_INPUTLINE_STATUS:
887cdf0e10cSrcweir 				DBG_ERROR( "Old update method. Use ScTabViewShell::UpdateInputHandler()." );
888cdf0e10cSrcweir 				break;
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 			case SID_SCENARIOS:										// Szenarios:
891cdf0e10cSrcweir 				if (!(rMark.IsMarked() || rMark.IsMultiMarked()))	// nur, wenn etwas selektiert
892cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
893cdf0e10cSrcweir 				break;
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 			case FID_NOTE_VISIBLE:
896cdf0e10cSrcweir 				{
897cdf0e10cSrcweir                     const ScPostIt* pNote = pDoc->GetNote( ScAddress( nPosX, nPosY, nTab ) );
898cdf0e10cSrcweir 					if ( pNote && pDoc->IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) )
899cdf0e10cSrcweir 						rSet.Put( SfxBoolItem( nWhich, pNote->IsCaptionShown() ) );
900cdf0e10cSrcweir 					else
901cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
902cdf0e10cSrcweir 				}
903cdf0e10cSrcweir 				break;
904cdf0e10cSrcweir 
905cdf0e10cSrcweir             case SID_DELETE_NOTE:
906cdf0e10cSrcweir                 {
907cdf0e10cSrcweir                     sal_Bool bEnable = sal_False;
908cdf0e10cSrcweir                     if ( rMark.IsMarked() || rMark.IsMultiMarked() )
909cdf0e10cSrcweir                     {
910cdf0e10cSrcweir                         if ( pDoc->IsSelectionEditable( rMark ) )
911cdf0e10cSrcweir                         {
912cdf0e10cSrcweir                             // look for at least one note in selection
913cdf0e10cSrcweir                             ScRangeList aRanges;
914cdf0e10cSrcweir                             rMark.FillRangeListWithMarks( &aRanges, sal_False );
915cdf0e10cSrcweir                             sal_uLong nCount = aRanges.Count();
916cdf0e10cSrcweir                             for (sal_uLong nPos=0; nPos<nCount && !bEnable; nPos++)
917cdf0e10cSrcweir                             {
918cdf0e10cSrcweir                                 ScCellIterator aCellIter( pDoc, *aRanges.GetObject(nPos) );
919cdf0e10cSrcweir                                 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell && !bEnable; pCell = aCellIter.GetNext() )
920cdf0e10cSrcweir                                     if ( pCell->HasNote() )
921cdf0e10cSrcweir                                         bEnable = sal_True;             // note found
922cdf0e10cSrcweir                             }
923cdf0e10cSrcweir                         }
924cdf0e10cSrcweir                     }
925cdf0e10cSrcweir                     else
926cdf0e10cSrcweir                     {
927cdf0e10cSrcweir                         bEnable = pDoc->IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) &&
928cdf0e10cSrcweir                                   pDoc->GetNote( ScAddress( nPosX, nPosY, nTab ) );
929cdf0e10cSrcweir                     }
930cdf0e10cSrcweir                     if ( !bEnable )
931cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
932cdf0e10cSrcweir                 }
933cdf0e10cSrcweir                 break;
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 			case SID_OPENDLG_CONSOLIDATE:
936cdf0e10cSrcweir 			case SCITEM_CONSOLIDATEDATA:
937cdf0e10cSrcweir 				{
938cdf0e10cSrcweir 					if(pDoc->GetChangeTrack()!=NULL)
939cdf0e10cSrcweir 								rSet.DisableItem( nWhich);
940cdf0e10cSrcweir 				}
941cdf0e10cSrcweir 				break;
942cdf0e10cSrcweir 
943cdf0e10cSrcweir             case SID_CHINESE_CONVERSION:
944cdf0e10cSrcweir             case SID_HANGUL_HANJA_CONVERSION:
945cdf0e10cSrcweir                 ScViewUtil::HideDisabledSlot( rSet, pData->GetBindings(), nWhich );
946cdf0e10cSrcweir             break;
947cdf0e10cSrcweir 
948cdf0e10cSrcweir             case FID_USE_NAME:
949cdf0e10cSrcweir                 {
950cdf0e10cSrcweir                     if ( pDocSh && pDocSh->IsDocShared() )
951cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
952cdf0e10cSrcweir                     else
953cdf0e10cSrcweir                     {
954cdf0e10cSrcweir                         ScRange aRange;
955cdf0e10cSrcweir                         if ( pData->GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
956cdf0e10cSrcweir                             rSet.DisableItem( nWhich );
957cdf0e10cSrcweir                     }
958cdf0e10cSrcweir                 }
959cdf0e10cSrcweir                 break;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir             case FID_DEFINE_NAME:
962cdf0e10cSrcweir             case FID_INSERT_NAME:
963cdf0e10cSrcweir             case SID_DEFINE_COLROWNAMERANGES:
964cdf0e10cSrcweir                 {
965cdf0e10cSrcweir                     if ( pDocSh && pDocSh->IsDocShared() )
966cdf0e10cSrcweir                     {
967cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
968cdf0e10cSrcweir                     }
969cdf0e10cSrcweir                 }
970cdf0e10cSrcweir                 break;
971cdf0e10cSrcweir 
972cdf0e10cSrcweir             case SID_SPELL_DIALOG:
973cdf0e10cSrcweir                 {
974cdf0e10cSrcweir                     if ( pDoc && pData && pDoc->IsTabProtected( pData->GetTabNo() ) )
975cdf0e10cSrcweir                     {
976cdf0e10cSrcweir                         bool bVisible = false;
977cdf0e10cSrcweir                         SfxViewFrame* pViewFrame = ( pTabViewShell ? pTabViewShell->GetViewFrame() : NULL );
978cdf0e10cSrcweir                         if ( pViewFrame && pViewFrame->HasChildWindow( nWhich ) )
979cdf0e10cSrcweir                         {
980cdf0e10cSrcweir                             SfxChildWindow* pChild = pViewFrame->GetChildWindow( nWhich );
981cdf0e10cSrcweir                             Window* pWin = ( pChild ? pChild->GetWindow() : NULL );
982cdf0e10cSrcweir                             if ( pWin && pWin->IsVisible() )
983cdf0e10cSrcweir                             {
984cdf0e10cSrcweir                                 bVisible = true;
985cdf0e10cSrcweir                             }
986cdf0e10cSrcweir                         }
987cdf0e10cSrcweir                         if ( !bVisible )
988cdf0e10cSrcweir                         {
989cdf0e10cSrcweir                             rSet.DisableItem( nWhich );
990cdf0e10cSrcweir                         }
991cdf0e10cSrcweir                     }
992cdf0e10cSrcweir                 }
993cdf0e10cSrcweir                 break;
994cdf0e10cSrcweir 
995cdf0e10cSrcweir 		} // switch ( nWitch )
996cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
997cdf0e10cSrcweir 	} // while ( nWitch )
998cdf0e10cSrcweir }
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir //------------------------------------------------------------------
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 
1004