xref: /trunk/main/sc/source/ui/view/cellsh.cxx (revision f120fe41)
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>
45*f120fe41SAndre Fischer #include <sfx2/sidebar/EnumContext.hxx>
46cdf0e10cSrcweir #include <svx/clipfmtitem.hxx>
47*f120fe41SAndre 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 
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 
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")));
90*f120fe41SAndre Fischer     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Cell));
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
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 
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 
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 
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 
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 );
380cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_BITMAP );
381cdf0e10cSrcweir 	lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBED_SOURCE );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 	if ( !bDraw )
384cdf0e10cSrcweir 	{
385cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_LINK );
386cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_STRING );
387cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_DIF );
388cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMAT_RTF );
389cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_HTML );
390cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_HTML_SIMPLE );
391cdf0e10cSrcweir         lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_BIFF_8 );
392cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_BIFF_5 );
393cdf0e10cSrcweir 	}
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	if ( !lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) )
396cdf0e10cSrcweir 		lcl_TestFormat( rFormats, aDataHelper, SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir //	Einfuegen, Inhalte einfuegen
400cdf0e10cSrcweir 
401cdf0e10cSrcweir sal_Bool lcl_IsCellPastePossible( const TransferableDataHelper& rData )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir 	sal_Bool bPossible = sal_False;
404cdf0e10cSrcweir 	if ( ScTransferObj::GetOwnClipboard( NULL ) || ScDrawTransferObj::GetOwnClipboard( NULL ) )
405cdf0e10cSrcweir 		bPossible = sal_True;
406cdf0e10cSrcweir 	else
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		if ( rData.HasFormat( SOT_FORMAT_BITMAP ) ||
409cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_GDIMETAFILE ) ||
410cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_SVXB ) ||
411cdf0e10cSrcweir 			 rData.HasFormat( FORMAT_PRIVATE ) ||
412cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_RTF ) ||
413cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) ||
414cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ) ||
415cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) ||
416cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) ||
417cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) ||
418cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMAT_STRING ) ||
419cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) ||
420cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_LINK ) ||
421cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_HTML ) ||
422cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_HTML_SIMPLE ) ||
423cdf0e10cSrcweir 			 rData.HasFormat( SOT_FORMATSTR_ID_DIF ) )
424cdf0e10cSrcweir 		{
425cdf0e10cSrcweir 			bPossible = sal_True;
426cdf0e10cSrcweir 		}
427cdf0e10cSrcweir 	}
428cdf0e10cSrcweir 	return bPossible;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 	if ( pDataHelper )
434cdf0e10cSrcweir 	{
435cdf0e10cSrcweir 		bPastePossible = lcl_IsCellPastePossible( *pDataHelper );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 		SfxBindings& rBindings = GetViewData()->GetBindings();
438cdf0e10cSrcweir 		rBindings.Invalidate( SID_PASTE );
439cdf0e10cSrcweir         rBindings.Invalidate( SID_PASTE_SPECIAL );
440cdf0e10cSrcweir 		rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 	return 0;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir void __EXPORT ScCellShell::GetClipState( SfxItemSet& rSet )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir // SID_PASTE
449cdf0e10cSrcweir // SID_PASTE_SPECIAL
450cdf0e10cSrcweir // SID_CLIPBOARD_FORMAT_ITEMS
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     if ( !pImpl->m_pClipEvtLstnr )
453cdf0e10cSrcweir 	{
454cdf0e10cSrcweir 		// create listener
455cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScCellShell, ClipboardChanged ) );
456cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->acquire();
457cdf0e10cSrcweir 		Window* pWin = GetViewData()->GetActiveWin();
458cdf0e10cSrcweir         pImpl->m_pClipEvtLstnr->AddRemoveListener( pWin, sal_True );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 		// get initial state
461cdf0e10cSrcweir 		TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
462cdf0e10cSrcweir 		bPastePossible = lcl_IsCellPastePossible( aDataHelper );
463cdf0e10cSrcweir 	}
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	sal_Bool bDisable = !bPastePossible;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	//	Zellschutz / Multiselektion
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	if (!bDisable)
470cdf0e10cSrcweir 	{
471cdf0e10cSrcweir 		SCCOL nCol = GetViewData()->GetCurX();
472cdf0e10cSrcweir 		SCROW nRow = GetViewData()->GetCurY();
473cdf0e10cSrcweir 		SCTAB nTab = GetViewData()->GetTabNo();
474cdf0e10cSrcweir 		ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
475cdf0e10cSrcweir 		if (!pDoc->IsBlockEditable( nTab, nCol,nRow, nCol,nRow ))
476cdf0e10cSrcweir 			bDisable = sal_True;
477cdf0e10cSrcweir         ScRange aDummy;
478cdf0e10cSrcweir         ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
479cdf0e10cSrcweir         if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
480cdf0e10cSrcweir 			bDisable = sal_True;
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	if (bDisable)
484cdf0e10cSrcweir 	{
485cdf0e10cSrcweir 		rSet.DisableItem( SID_PASTE );
486cdf0e10cSrcweir         rSet.DisableItem( SID_PASTE_SPECIAL );
487cdf0e10cSrcweir 		rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS );
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir 	else if ( rSet.GetItemState( SID_CLIPBOARD_FORMAT_ITEMS ) != SFX_ITEM_UNKNOWN )
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
492cdf0e10cSrcweir 		GetPossibleClipboardFormats( aFormats );
493cdf0e10cSrcweir 		rSet.Put( aFormats );
494cdf0e10cSrcweir 	}
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir //	only SID_HYPERLINK_GETLINK:
498cdf0e10cSrcweir 
499cdf0e10cSrcweir void ScCellShell::GetHLinkState( SfxItemSet& rSet )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir 	//	always return an item (or inserting will be disabled)
502cdf0e10cSrcweir 	//	if the cell at the cursor contains only a link, return that link
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	SvxHyperlinkItem aHLinkItem;
505cdf0e10cSrcweir 	if ( !GetViewData()->GetView()->HasBookmarkAtCursor( &aHLinkItem ) )
506cdf0e10cSrcweir 	{
507cdf0e10cSrcweir 		//!	put selected text into item?
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 	rSet.Put(aHLinkItem);
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir void ScCellShell::GetState(SfxItemSet &rSet)
514cdf0e10cSrcweir {
515cdf0e10cSrcweir 	// removed: SID_BORDER_OBJECT (old Basic)
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
518cdf0e10cSrcweir //     sal_Bool bOle = pTabViewShell->GetViewFrame()->GetFrame().IsInPlace();
519cdf0e10cSrcweir // 	sal_Bool bTabProt = GetViewData()->GetDocument()->IsTabProtected(GetViewData()->GetTabNo());
520cdf0e10cSrcweir 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
521cdf0e10cSrcweir     ScViewData* pData       = GetViewData();
522cdf0e10cSrcweir 	ScDocument* pDoc		= pData->GetDocument();
523cdf0e10cSrcweir 	ScMarkData& rMark		= pData->GetMarkData();
524cdf0e10cSrcweir 	SCCOL		nPosX		= pData->GetCurX();
525cdf0e10cSrcweir 	SCROW		nPosY		= pData->GetCurY();
526cdf0e10cSrcweir 	SCTAB		nTab		= pData->GetTabNo();
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
529cdf0e10cSrcweir 	SCTAB nTabSelCount = rMark.GetSelectCount();
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
534cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
535cdf0e10cSrcweir 	while ( nWhich )
536cdf0e10cSrcweir 	{
537cdf0e10cSrcweir 		switch ( nWhich )
538cdf0e10cSrcweir 		{
539cdf0e10cSrcweir 			case SID_DETECTIVE_REFRESH:
540cdf0e10cSrcweir 				if (!pDoc->HasDetectiveOperations())
541cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
542cdf0e10cSrcweir 				break;
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 			case SID_RANGE_ADDRESS:
545cdf0e10cSrcweir 				{
546cdf0e10cSrcweir 					ScRange aRange;
547cdf0e10cSrcweir 					if ( pData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
548cdf0e10cSrcweir 					{
549cdf0e10cSrcweir 						String aStr;
550cdf0e10cSrcweir 						sal_uInt16 nFlags = SCA_VALID | SCA_TAB_3D;
551cdf0e10cSrcweir 						aRange.Format(aStr,nFlags,pDoc);
552cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich, aStr ) );
553cdf0e10cSrcweir 					}
554cdf0e10cSrcweir 				}
555cdf0e10cSrcweir 				break;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 			case SID_RANGE_NOTETEXT:
558cdf0e10cSrcweir 				{
559cdf0e10cSrcweir 					//	#43343# always take cursor position, do not use top-left cell of selection
560cdf0e10cSrcweir 					ScAddress aPos( nPosX, nPosY, nTab );
561cdf0e10cSrcweir 					String aNoteText;
562cdf0e10cSrcweir 					if ( const ScPostIt* pNote = pDoc->GetNote( aPos ) )
563cdf0e10cSrcweir                         aNoteText = pNote->GetText();
564cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aNoteText ) );
565cdf0e10cSrcweir 				}
566cdf0e10cSrcweir 				break;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 			case SID_RANGE_ROW:
569cdf0e10cSrcweir 				rSet.Put( SfxInt32Item( nWhich, nPosY+1 ) );
570cdf0e10cSrcweir 				break;
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 			case SID_RANGE_COL:
573cdf0e10cSrcweir 				rSet.Put( SfxInt16Item( nWhich, nPosX+1 ) );
574cdf0e10cSrcweir 				break;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 			case SID_RANGE_TABLE:
577cdf0e10cSrcweir 				rSet.Put( SfxInt16Item( nWhich, nTab+1 ) );
578cdf0e10cSrcweir 				break;
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 			case SID_RANGE_VALUE:
581cdf0e10cSrcweir 				{
582cdf0e10cSrcweir 					double nValue;
583cdf0e10cSrcweir 					pDoc->GetValue( nPosX, nPosY, nTab, nValue );
584cdf0e10cSrcweir 					rSet.Put( ScDoubleItem( nWhich, nValue ) );
585cdf0e10cSrcweir 				}
586cdf0e10cSrcweir 				break;
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 			case SID_RANGE_FORMULA:
589cdf0e10cSrcweir 				{
590cdf0e10cSrcweir 					String aString;
591cdf0e10cSrcweir 					pDoc->GetFormula( nPosX, nPosY, nTab, aString );
592cdf0e10cSrcweir 					if( aString.Len() == 0 )
593cdf0e10cSrcweir 					{
594cdf0e10cSrcweir 						pDoc->GetInputString( nPosX, nPosY, nTab, aString );
595cdf0e10cSrcweir 					}
596cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aString ) );
597cdf0e10cSrcweir 				}
598cdf0e10cSrcweir 				break;
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 			case SID_RANGE_TEXTVALUE:
601cdf0e10cSrcweir 				{
602cdf0e10cSrcweir 					String aString;
603cdf0e10cSrcweir 					pDoc->GetString( nPosX, nPosY, nTab, aString );
604cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aString ) );
605cdf0e10cSrcweir 				}
606cdf0e10cSrcweir 				break;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 			case SID_STATUS_SELMODE:
609cdf0e10cSrcweir 				{
610cdf0e10cSrcweir 					/* 0: STD	Click hebt Sel auf
611cdf0e10cSrcweir 					 * 1: ER	Click erweitert Selektion
612cdf0e10cSrcweir 					 * 2: ERG	Click definiert weitere Selektion
613cdf0e10cSrcweir 					 */
614cdf0e10cSrcweir 					sal_uInt16 nMode = pTabViewShell->GetLockedModifiers();
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 					switch ( nMode )
617cdf0e10cSrcweir 					{
618cdf0e10cSrcweir 						case KEY_SHIFT: nMode = 1;	break;
619cdf0e10cSrcweir 						case KEY_MOD1:	nMode = 2;	break; // Control-Taste
620cdf0e10cSrcweir 						case 0:
621cdf0e10cSrcweir 						default:
622cdf0e10cSrcweir 							nMode = 0;
623cdf0e10cSrcweir 					}
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 					rSet.Put( SfxUInt16Item( nWhich, nMode ) );
626cdf0e10cSrcweir 				}
627cdf0e10cSrcweir 				break;
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 			case SID_STATUS_DOCPOS:
630cdf0e10cSrcweir 				{
631cdf0e10cSrcweir 					String	aStr( ScGlobal::GetRscString( STR_TABLE ) );
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 					aStr += ' ';
634cdf0e10cSrcweir 					aStr += String::CreateFromInt32( nTab + 1 );
635cdf0e10cSrcweir 					aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " ));
636cdf0e10cSrcweir 					aStr += String::CreateFromInt32( nTabCount );
637cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aStr ) );
638cdf0e10cSrcweir 				}
639cdf0e10cSrcweir 				break;
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 			//	Summe etc. mit Datum/Zeit/Fehler/Pos&Groesse zusammengefasst
642cdf0e10cSrcweir 
643cdf0e10cSrcweir             // #i34458# The SfxStringItem belongs only into SID_TABLE_CELL. It no longer has to be
644cdf0e10cSrcweir             // duplicated in SID_ATTR_POSITION or SID_ATTR_SIZE for SvxPosSizeStatusBarControl.
645cdf0e10cSrcweir 			case SID_TABLE_CELL:
646cdf0e10cSrcweir 				{
647cdf0e10cSrcweir 					//	Testen, ob Fehler unter Cursor
648cdf0e10cSrcweir 					//	(nicht pDoc->GetErrCode, um keine zirkulaeren Referenzen auszuloesen)
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 					// In interpreter may happen via rescheduled Basic
651cdf0e10cSrcweir 					if ( pDoc->IsInInterpreter() )
652cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich,
653cdf0e10cSrcweir 							String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("...")) ) );
654cdf0e10cSrcweir 					else
655cdf0e10cSrcweir 					{
656cdf0e10cSrcweir 						sal_uInt16 nErrCode = 0;
657cdf0e10cSrcweir 						ScBaseCell* pCell;
658cdf0e10cSrcweir 						pDoc->GetCell( nPosX, nPosY, nTab, pCell );
659cdf0e10cSrcweir 						if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
660cdf0e10cSrcweir 						{
661cdf0e10cSrcweir 							ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
662cdf0e10cSrcweir 							if (!pFCell->IsRunning())
663cdf0e10cSrcweir 								nErrCode = pFCell->GetErrCode();
664cdf0e10cSrcweir 						}
665cdf0e10cSrcweir 
666cdf0e10cSrcweir                         String aFuncStr;
667cdf0e10cSrcweir                         if ( pTabViewShell->GetFunction( aFuncStr, nErrCode ) )
668cdf0e10cSrcweir                             rSet.Put( SfxStringItem( nWhich, aFuncStr ) );
669cdf0e10cSrcweir 					}
670cdf0e10cSrcweir 				}
671cdf0e10cSrcweir 				break;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 			case SID_DATA_SELECT:
674cdf0e10cSrcweir                 // HasSelectionData includes column content and validity,
675cdf0e10cSrcweir                 // page fields have to be checked separately.
676cdf0e10cSrcweir                 if ( !pDoc->HasSelectionData( nPosX, nPosY, nTab ) &&
677cdf0e10cSrcweir                      !pTabViewShell->HasPageFieldDataAtCursor() )
678cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
679cdf0e10cSrcweir 				break;
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 			case SID_STATUS_SUM:
682cdf0e10cSrcweir 				{
683cdf0e10cSrcweir 					String aFuncStr;
684cdf0e10cSrcweir 					if ( pTabViewShell->GetFunction( aFuncStr ) )
685cdf0e10cSrcweir 						rSet.Put( SfxStringItem( nWhich, aFuncStr ) );
686cdf0e10cSrcweir 				}
687cdf0e10cSrcweir 				break;
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 			case FID_MERGE_ON:
690cdf0e10cSrcweir 				if ( pDoc->GetChangeTrack() || !pTabViewShell->TestMergeCells() )
691cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
692cdf0e10cSrcweir 				break;
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 			case FID_MERGE_OFF:
695cdf0e10cSrcweir 				if ( pDoc->GetChangeTrack() || !pTabViewShell->TestRemoveMerge() )
696cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
697cdf0e10cSrcweir 				break;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir             case FID_MERGE_TOGGLE:
700cdf0e10cSrcweir                 if ( pDoc->GetChangeTrack() )
701cdf0e10cSrcweir                     rSet.DisableItem( nWhich );
702cdf0e10cSrcweir                 else
703cdf0e10cSrcweir                 {
704cdf0e10cSrcweir                     bool bCanMerge = pTabViewShell->TestMergeCells();
705cdf0e10cSrcweir                     bool bCanSplit = pTabViewShell->TestRemoveMerge();
706cdf0e10cSrcweir                     if( !bCanMerge && !bCanSplit )
707cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
708cdf0e10cSrcweir                     else
709cdf0e10cSrcweir                         rSet.Put( SfxBoolItem( nWhich, bCanSplit ) );
710cdf0e10cSrcweir                 }
711cdf0e10cSrcweir                 break;
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 			case FID_INS_ROWBRK:
714cdf0e10cSrcweir                 if ( nPosY==0 || (pDoc->HasRowBreak(nPosY, nTab) & BREAK_MANUAL) )
715cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
716cdf0e10cSrcweir 				break;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 			case FID_INS_COLBRK:
719cdf0e10cSrcweir                 if ( nPosX==0 || (pDoc->HasColBreak(nPosX, nTab) & BREAK_MANUAL) )
720cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
721cdf0e10cSrcweir 				break;
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 			case FID_DEL_ROWBRK:
724cdf0e10cSrcweir                 if ( nPosY==0 || (pDoc->HasRowBreak(nPosY, nTab) & BREAK_MANUAL) == 0 )
725cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
726cdf0e10cSrcweir 				break;
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 			case FID_DEL_COLBRK:
729cdf0e10cSrcweir                 if ( nPosX==0 || (pDoc->HasColBreak(nPosX, nTab) & BREAK_MANUAL) == 0 )
730cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
731cdf0e10cSrcweir 				break;
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 			case FID_FILL_TAB:
734cdf0e10cSrcweir 				if ( nTabSelCount < 2 )
735cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
736cdf0e10cSrcweir 				break;
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 			case SID_SELECT_SCENARIO:
739cdf0e10cSrcweir 				{
740cdf0e10cSrcweir                     // ScDocument* pDoc = GetViewData()->GetDocument();
741cdf0e10cSrcweir                     // SCTAB       nTab = GetViewData()->GetTabNo();
742cdf0e10cSrcweir 					List		aList;
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 					Color	aDummyCol;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 					if ( !pDoc->IsScenario(nTab) )
747cdf0e10cSrcweir 					{
748cdf0e10cSrcweir 						String aStr;
749cdf0e10cSrcweir 						sal_uInt16 nFlags;
750cdf0e10cSrcweir 						SCTAB nScTab = nTab + 1;
751cdf0e10cSrcweir 						String aProtect;
752cdf0e10cSrcweir 						bool bSheetProtected = pDoc->IsTabProtected(nTab);
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 						while ( pDoc->IsScenario(nScTab) )
755cdf0e10cSrcweir 						{
756cdf0e10cSrcweir 							pDoc->GetName( nScTab, aStr );
757cdf0e10cSrcweir 							aList.Insert( new String( aStr ), LIST_APPEND );
758cdf0e10cSrcweir 							pDoc->GetScenarioData( nScTab, aStr, aDummyCol, nFlags );
759cdf0e10cSrcweir 							aList.Insert( new String( aStr ), LIST_APPEND );
760cdf0e10cSrcweir 							// Protection is sal_True if both Sheet and Scenario are protected
761cdf0e10cSrcweir 							aProtect = (bSheetProtected && (nFlags & SC_SCENARIO_PROTECT)) ? '1' : '0';
762cdf0e10cSrcweir 							aList.Insert( new String( aProtect), LIST_APPEND );
763cdf0e10cSrcweir 							++nScTab;
764cdf0e10cSrcweir 						}
765cdf0e10cSrcweir 					}
766cdf0e10cSrcweir 					else
767cdf0e10cSrcweir 					{
768cdf0e10cSrcweir 						String	aComment;
769cdf0e10cSrcweir 						sal_uInt16	nDummyFlags;
770cdf0e10cSrcweir 						pDoc->GetScenarioData( nTab, aComment, aDummyCol, nDummyFlags );
771cdf0e10cSrcweir 						DBG_ASSERT( aList.Count() == 0, "List not empty!" );
772cdf0e10cSrcweir 						aList.Insert( new String( aComment ) );
773cdf0e10cSrcweir 					}
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 					rSet.Put( SfxStringListItem( nWhich, &aList ) );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 					sal_uLong nCount = aList.Count();
778cdf0e10cSrcweir 					for ( sal_uLong i=0; i<nCount; i++ )
779cdf0e10cSrcweir 						delete (String*) aList.GetObject(i);
780cdf0e10cSrcweir 				}
781cdf0e10cSrcweir 				break;
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 			case FID_ROW_HIDE:
784cdf0e10cSrcweir 			case FID_ROW_SHOW:
785cdf0e10cSrcweir 			case FID_COL_HIDE:
786cdf0e10cSrcweir 			case FID_COL_SHOW:
787cdf0e10cSrcweir 			case FID_COL_OPT_WIDTH:
788cdf0e10cSrcweir 			case FID_ROW_OPT_HEIGHT:
789cdf0e10cSrcweir 			case FID_DELETE_CELL:
790cdf0e10cSrcweir 				if ( pDoc->IsTabProtected(nTab) || pDocSh->IsReadOnly())
791cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
792cdf0e10cSrcweir 				break;
793cdf0e10cSrcweir 
794cdf0e10cSrcweir /*	Zellschutz bei selektierten Zellen wird bei anderen Funktionen auch nicht abgefragt...
795cdf0e10cSrcweir 			case SID_DELETE:
796cdf0e10cSrcweir 				{
797cdf0e10cSrcweir 					if ( pDoc->IsTabProtected(nTab) )
798cdf0e10cSrcweir 					{
799cdf0e10cSrcweir 						const SfxItemSet&		rAttrSet  = GetSelectionPattern()->GetItemSet();
800cdf0e10cSrcweir 						const ScProtectionAttr& rProtAttr = (const ScProtectionAttr&)rAttrSet.Get( ATTR_PROTECTION, sal_True );
801cdf0e10cSrcweir 						if ( rProtAttr.GetProtection() )
802cdf0e10cSrcweir 							rSet.DisableItem( nWhich );
803cdf0e10cSrcweir 					}
804cdf0e10cSrcweir 				}
805cdf0e10cSrcweir 				break;
806cdf0e10cSrcweir */
807cdf0e10cSrcweir 			case SID_OUTLINE_MAKE:
808cdf0e10cSrcweir 				{
809cdf0e10cSrcweir     				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
810cdf0e10cSrcweir                 							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
811cdf0e10cSrcweir                     {
812cdf0e10cSrcweir                         //! test for data pilot operation
813cdf0e10cSrcweir                     }
814cdf0e10cSrcweir 					else if (pDoc->GetChangeTrack()!=NULL || GetViewData()->IsMultiMarked())
815cdf0e10cSrcweir 					{
816cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
817cdf0e10cSrcweir 					}
818cdf0e10cSrcweir 				}
819cdf0e10cSrcweir 				break;
820cdf0e10cSrcweir 			case SID_OUTLINE_SHOW:
821cdf0e10cSrcweir 				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
822cdf0e10cSrcweir             							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
823cdf0e10cSrcweir                 {
824cdf0e10cSrcweir                     //! test for data pilot operation
825cdf0e10cSrcweir                 }
826cdf0e10cSrcweir 				else if (!pTabViewShell->OutlinePossible(sal_False))
827cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
828cdf0e10cSrcweir 				break;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 			case SID_OUTLINE_HIDE:
831cdf0e10cSrcweir 				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
832cdf0e10cSrcweir             							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
833cdf0e10cSrcweir                 {
834cdf0e10cSrcweir                     //! test for data pilot operation
835cdf0e10cSrcweir                 }
836cdf0e10cSrcweir 				else if (!pTabViewShell->OutlinePossible(sal_True))
837cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
838cdf0e10cSrcweir 				break;
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 			case SID_OUTLINE_REMOVE:
841cdf0e10cSrcweir 				{
842cdf0e10cSrcweir     				if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
843cdf0e10cSrcweir                 							GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
844cdf0e10cSrcweir                     {
845cdf0e10cSrcweir                         //! test for data pilot operation
846cdf0e10cSrcweir                     }
847cdf0e10cSrcweir                     else
848cdf0e10cSrcweir                     {
849cdf0e10cSrcweir     					sal_Bool bCol, bRow;
850cdf0e10cSrcweir     					pTabViewShell->TestRemoveOutline( bCol, bRow );
851cdf0e10cSrcweir     					if ( !bCol && !bRow )
852cdf0e10cSrcweir     						rSet.DisableItem( nWhich );
853cdf0e10cSrcweir                     }
854cdf0e10cSrcweir 				}
855cdf0e10cSrcweir 				break;
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 			case FID_COL_WIDTH:
858cdf0e10cSrcweir 				{
859cdf0e10cSrcweir 					//GetViewData()->GetCurX();
860cdf0e10cSrcweir 					SfxUInt16Item aWidthItem( FID_COL_WIDTH, pDoc->GetColWidth( nPosX , nTab) );
861cdf0e10cSrcweir 					rSet.Put( aWidthItem );
862cdf0e10cSrcweir 					if ( pDocSh->IsReadOnly())
863cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 					//XXX Disablen wenn nicht eindeutig
866cdf0e10cSrcweir 				}
867cdf0e10cSrcweir 				break;
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 			case FID_ROW_HEIGHT:
870cdf0e10cSrcweir 				{
871cdf0e10cSrcweir 					//GetViewData()->GetCurY();
872cdf0e10cSrcweir 					SfxUInt16Item aHeightItem( FID_ROW_HEIGHT, pDoc->GetRowHeight( nPosY , nTab) );
873cdf0e10cSrcweir 					rSet.Put( aHeightItem );
874cdf0e10cSrcweir 					//XXX Disablen wenn nicht eindeutig
875cdf0e10cSrcweir 					if ( pDocSh->IsReadOnly())
876cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
877cdf0e10cSrcweir 				}
878cdf0e10cSrcweir 				break;
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 			case SID_DETECTIVE_FILLMODE:
881cdf0e10cSrcweir 				rSet.Put(SfxBoolItem( nWhich, pTabViewShell->IsAuditShell() ));
882cdf0e10cSrcweir 				break;
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 			case FID_INPUTLINE_STATUS:
885cdf0e10cSrcweir 				DBG_ERROR( "Old update method. Use ScTabViewShell::UpdateInputHandler()." );
886cdf0e10cSrcweir 				break;
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 			case SID_SCENARIOS:										// Szenarios:
889cdf0e10cSrcweir 				if (!(rMark.IsMarked() || rMark.IsMultiMarked()))	// nur, wenn etwas selektiert
890cdf0e10cSrcweir 					rSet.DisableItem( nWhich );
891cdf0e10cSrcweir 				break;
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 			case FID_NOTE_VISIBLE:
894cdf0e10cSrcweir 				{
895cdf0e10cSrcweir                     const ScPostIt* pNote = pDoc->GetNote( ScAddress( nPosX, nPosY, nTab ) );
896cdf0e10cSrcweir 					if ( pNote && pDoc->IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) )
897cdf0e10cSrcweir 						rSet.Put( SfxBoolItem( nWhich, pNote->IsCaptionShown() ) );
898cdf0e10cSrcweir 					else
899cdf0e10cSrcweir 						rSet.DisableItem( nWhich );
900cdf0e10cSrcweir 				}
901cdf0e10cSrcweir 				break;
902cdf0e10cSrcweir 
903cdf0e10cSrcweir             case SID_DELETE_NOTE:
904cdf0e10cSrcweir                 {
905cdf0e10cSrcweir                     sal_Bool bEnable = sal_False;
906cdf0e10cSrcweir                     if ( rMark.IsMarked() || rMark.IsMultiMarked() )
907cdf0e10cSrcweir                     {
908cdf0e10cSrcweir                         if ( pDoc->IsSelectionEditable( rMark ) )
909cdf0e10cSrcweir                         {
910cdf0e10cSrcweir                             // look for at least one note in selection
911cdf0e10cSrcweir                             ScRangeList aRanges;
912cdf0e10cSrcweir                             rMark.FillRangeListWithMarks( &aRanges, sal_False );
913cdf0e10cSrcweir                             sal_uLong nCount = aRanges.Count();
914cdf0e10cSrcweir                             for (sal_uLong nPos=0; nPos<nCount && !bEnable; nPos++)
915cdf0e10cSrcweir                             {
916cdf0e10cSrcweir                                 ScCellIterator aCellIter( pDoc, *aRanges.GetObject(nPos) );
917cdf0e10cSrcweir                                 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell && !bEnable; pCell = aCellIter.GetNext() )
918cdf0e10cSrcweir                                     if ( pCell->HasNote() )
919cdf0e10cSrcweir                                         bEnable = sal_True;             // note found
920cdf0e10cSrcweir                             }
921cdf0e10cSrcweir                         }
922cdf0e10cSrcweir                     }
923cdf0e10cSrcweir                     else
924cdf0e10cSrcweir                     {
925cdf0e10cSrcweir                         bEnable = pDoc->IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) &&
926cdf0e10cSrcweir                                   pDoc->GetNote( ScAddress( nPosX, nPosY, nTab ) );
927cdf0e10cSrcweir                     }
928cdf0e10cSrcweir                     if ( !bEnable )
929cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
930cdf0e10cSrcweir                 }
931cdf0e10cSrcweir                 break;
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 			case SID_OPENDLG_CONSOLIDATE:
934cdf0e10cSrcweir 			case SCITEM_CONSOLIDATEDATA:
935cdf0e10cSrcweir 				{
936cdf0e10cSrcweir 					if(pDoc->GetChangeTrack()!=NULL)
937cdf0e10cSrcweir 								rSet.DisableItem( nWhich);
938cdf0e10cSrcweir 				}
939cdf0e10cSrcweir 				break;
940cdf0e10cSrcweir 
941cdf0e10cSrcweir             case SID_CHINESE_CONVERSION:
942cdf0e10cSrcweir             case SID_HANGUL_HANJA_CONVERSION:
943cdf0e10cSrcweir                 ScViewUtil::HideDisabledSlot( rSet, pData->GetBindings(), nWhich );
944cdf0e10cSrcweir             break;
945cdf0e10cSrcweir 
946cdf0e10cSrcweir             case FID_USE_NAME:
947cdf0e10cSrcweir                 {
948cdf0e10cSrcweir                     if ( pDocSh && pDocSh->IsDocShared() )
949cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
950cdf0e10cSrcweir                     else
951cdf0e10cSrcweir                     {
952cdf0e10cSrcweir                         ScRange aRange;
953cdf0e10cSrcweir                         if ( pData->GetSimpleArea( aRange ) != SC_MARK_SIMPLE )
954cdf0e10cSrcweir                             rSet.DisableItem( nWhich );
955cdf0e10cSrcweir                     }
956cdf0e10cSrcweir                 }
957cdf0e10cSrcweir                 break;
958cdf0e10cSrcweir 
959cdf0e10cSrcweir             case FID_DEFINE_NAME:
960cdf0e10cSrcweir             case FID_INSERT_NAME:
961cdf0e10cSrcweir             case SID_DEFINE_COLROWNAMERANGES:
962cdf0e10cSrcweir                 {
963cdf0e10cSrcweir                     if ( pDocSh && pDocSh->IsDocShared() )
964cdf0e10cSrcweir                     {
965cdf0e10cSrcweir                         rSet.DisableItem( nWhich );
966cdf0e10cSrcweir                     }
967cdf0e10cSrcweir                 }
968cdf0e10cSrcweir                 break;
969cdf0e10cSrcweir 
970cdf0e10cSrcweir             case SID_SPELL_DIALOG:
971cdf0e10cSrcweir                 {
972cdf0e10cSrcweir                     if ( pDoc && pData && pDoc->IsTabProtected( pData->GetTabNo() ) )
973cdf0e10cSrcweir                     {
974cdf0e10cSrcweir                         bool bVisible = false;
975cdf0e10cSrcweir                         SfxViewFrame* pViewFrame = ( pTabViewShell ? pTabViewShell->GetViewFrame() : NULL );
976cdf0e10cSrcweir                         if ( pViewFrame && pViewFrame->HasChildWindow( nWhich ) )
977cdf0e10cSrcweir                         {
978cdf0e10cSrcweir                             SfxChildWindow* pChild = pViewFrame->GetChildWindow( nWhich );
979cdf0e10cSrcweir                             Window* pWin = ( pChild ? pChild->GetWindow() : NULL );
980cdf0e10cSrcweir                             if ( pWin && pWin->IsVisible() )
981cdf0e10cSrcweir                             {
982cdf0e10cSrcweir                                 bVisible = true;
983cdf0e10cSrcweir                             }
984cdf0e10cSrcweir                         }
985cdf0e10cSrcweir                         if ( !bVisible )
986cdf0e10cSrcweir                         {
987cdf0e10cSrcweir                             rSet.DisableItem( nWhich );
988cdf0e10cSrcweir                         }
989cdf0e10cSrcweir                     }
990cdf0e10cSrcweir                 }
991cdf0e10cSrcweir                 break;
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 		} // switch ( nWitch )
994cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
995cdf0e10cSrcweir 	} // while ( nWitch )
996cdf0e10cSrcweir }
997cdf0e10cSrcweir 
998cdf0e10cSrcweir //------------------------------------------------------------------
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir 
1002