xref: /aoo42x/main/sc/source/ui/drawfunc/drawsh2.cxx (revision ee093554)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 //------------------------------------------------------------------
28 #include <com/sun/star/embed/EmbedMisc.hpp>
29 
30 #include "scitems.hxx"
31 #include <editeng/eeitem.hxx>
32 #include <editeng/sizeitem.hxx>
33 #include <svx/svdpagv.hxx>
34 #include <svx/xdef.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <svl/ptitem.hxx>
39 #include <svl/whiter.hxx>
40 #include <svx/svdobj.hxx>
41 #include <svx/svdouno.hxx>
42 #include <svx/extrusionbar.hxx>
43 #include <svx/fontworkbar.hxx>
44 
45 #include "drawsh.hxx"
46 #include "drawview.hxx"
47 #include "viewdata.hxx"
48 #include "sc.hrc"
49 #include "tabvwsh.hxx"
50 #include "document.hxx"
51 #include "drwlayer.hxx"
52 #include "userdat.hxx"
53 #include <svx/svdoole2.hxx>
54 #include <svx/svdocapt.hxx>
55 
56 sal_uInt16 ScGetFontWorkId();		// in drtxtob
57 
58 using namespace com::sun::star;
59 
60 //------------------------------------------------------------------
61 
62 ScDrawShell::ScDrawShell( ScViewData* pData ) :
63 	SfxShell(pData->GetViewShell()),
64 	pViewData( pData )
65 {
66 	SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
67     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
68     SetUndoManager( pMgr );
69     if ( !pViewData->GetDocument()->IsUndoEnabled() )
70     {
71         pMgr->SetMaxUndoActionCount( 0 );
72     }
73 	SetHelpId( HID_SCSHELL_DRAWSH );
74 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Drawing")));
75 }
76 
77 ScDrawShell::~ScDrawShell()
78 {
79 }
80 
81 void ScDrawShell::GetState( SfxItemSet& rSet )			// Zustaende / Toggles
82 {
83 	ScDrawView* pView	 = pViewData->GetScDrawView();
84 	SdrDragMode eMode	 = pView->GetDragMode();
85 
86 	rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
87 	rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
88 	rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
89 
90 	sal_uInt16 nFWId = ScGetFontWorkId();
91 	SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
92 	rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
93 
94         // Notes always default to Page anchor.
95 	bool bDisableAnchor = false;
96 	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
97 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
98 	if ( nMarkCount == 1 )
99 	{
100         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
101         if( ScDrawLayer::IsNoteCaption( pObj ) )
102 	    {
103             bDisableAnchor = true;
104             rSet.DisableItem( SID_ANCHOR_PAGE );
105             rSet.DisableItem( SID_ANCHOR_CELL );
106 	    }
107 	}
108 
109 	if ( !bDisableAnchor )
110 	{
111 	    switch( pView->GetAnchor() )
112 	    {
113 		case SCA_PAGE:
114 	        rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_True ) );
115 	        rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_False ) );
116 		break;
117 
118 		case SCA_CELL:
119 		rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_False ) );
120 		rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_True ) );
121 		break;
122 
123 		default:
124 		rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_False ) );
125 		rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_False ) );
126 		break;
127 	    }
128 	}
129 }
130 
131 void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )		// Funktionen disablen
132 {
133 	ScDrawView* pView = pViewData->GetScDrawView();
134 
135 	//	#111711# call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
136 	//	is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
137 	if (!pView->IsMirrorAllowed(sal_True,sal_True))
138 	{
139 		rSet.DisableItem( SID_MIRROR_HORIZONTAL );
140 		rSet.DisableItem( SID_MIRROR_VERTICAL );
141 		rSet.DisableItem( SID_FLIP_HORIZONTAL );
142 		rSet.DisableItem( SID_FLIP_VERTICAL );
143 	}
144 
145 	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
146 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
147 
148 	if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
149 		rSet.DisableItem( SID_GROUP );
150 	if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
151 		rSet.DisableItem( SID_UNGROUP );
152 	if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
153 		rSet.DisableItem( SID_ENTER_GROUP );
154 	if ( !pView->IsGroupEntered() )
155 		rSet.DisableItem( SID_LEAVE_GROUP );
156 
157 	if ( nMarkCount <= 1 )						// nichts oder nur ein Objekt selektiert
158 	{
159 			//	Ausrichtung
160 		rSet.DisableItem( SID_OBJECT_ALIGN_LEFT );		// keine Ausrichtung an der Seite
161 		rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
162 		rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
163 		rSet.DisableItem( SID_OBJECT_ALIGN_UP );
164 		rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
165 		rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
166 
167         // pseudo slots for Format menu
168         rSet.DisableItem( SID_ALIGN_ANY_LEFT );
169         rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
170         rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
171         rSet.DisableItem( SID_ALIGN_ANY_TOP );
172         rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
173         rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
174 	}
175 
176     // do not change layer of form controls
177     // #158385# #i83729# do not change layer of cell notes (on internal layer)
178 	if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
179 	{
180 		rSet.DisableItem( SID_OBJECT_HEAVEN );
181 		rSet.DisableItem( SID_OBJECT_HELL );
182 	}
183 	else
184 	{
185 		if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
186 		{
187 			rSet.DisableItem( SID_OBJECT_HEAVEN );
188 		}
189 		else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
190 		{
191 			rSet.DisableItem( SID_OBJECT_HELL );
192 		}
193 	}
194 
195 	sal_Bool bCanRename = sal_False;
196     if ( nMarkCount > 1 )
197     {
198 #ifdef ISSUE66550_HLINK_FOR_SHAPES
199         // no hypelink options for a selected group
200         rSet.DisableItem( SID_DRAW_HLINK_EDIT );
201         rSet.DisableItem( SID_DRAW_HLINK_DELETE );
202         rSet.DisableItem( SID_OPEN_HYPERLINK );
203 #endif
204     }
205     else if ( nMarkCount == 1 )
206 	{
207         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
208 #ifdef ISSUE66550_HLINK_FOR_SHAPES
209         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
210         if ( !pInfo || (pInfo->GetHlink().getLength() == 0) )
211         {
212             rSet.DisableItem( SID_DRAW_HLINK_DELETE );
213             rSet.DisableItem( SID_OPEN_HYPERLINK );
214         }
215 #endif
216         SdrLayerID nLayerID = pObj->GetLayer();
217         if ( nLayerID != SC_LAYER_INTERN )
218             bCanRename = sal_True;                          // #i51351# anything except internal objects can be renamed
219 
220         // #91929#; don't show original size entry if not possible
221         sal_uInt16 nObjType = pObj->GetObjIdentifier();
222         if ( nObjType == OBJ_OLE2 )
223         {
224             SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
225             if (pOleObj->GetObjRef().is() &&
226                 ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
227                 //TODO/LATER: why different slots in Draw and Calc?
228                 rSet.DisableItem(SID_ORIGINALSIZE);
229         }
230         else if ( nObjType == OBJ_CAPTION )
231         {
232             if ( nLayerID == SC_LAYER_INTERN )
233             {
234                 // SdrCaptionObj() Notes cannot be cut/copy in isolation from
235                 // their cells.
236                 rSet.DisableItem( SID_CUT );
237                 rSet.DisableItem( SID_COPY );
238                 // Notes always default to Page anchor.
239                 rSet.DisableItem( SID_ANCHOR_TOGGLE );
240             }
241         }
242 	}
243 	if ( !bCanRename )
244 	{
245 		// #i68101#
246 		rSet.DisableItem( SID_RENAME_OBJECT );
247 		rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
248 	}
249 
250 	if ( !nMarkCount )							// nichts selektiert
251 	{
252 			//	Anordnung
253 		rSet.DisableItem( SID_FRAME_UP );
254 		rSet.DisableItem( SID_FRAME_DOWN );
255 		rSet.DisableItem( SID_FRAME_TO_TOP );
256 		rSet.DisableItem( SID_FRAME_TO_BOTTOM );
257 			//	Clipboard / loeschen
258 		rSet.DisableItem( SID_DELETE );
259 		rSet.DisableItem( SID_DELETE_CONTENTS );
260 		rSet.DisableItem( SID_CUT );
261 		rSet.DisableItem( SID_COPY );
262 			//	sonstiges
263 		rSet.DisableItem( SID_ANCHOR_TOGGLE );
264 		rSet.DisableItem( SID_ORIGINALSIZE );
265 		rSet.DisableItem( SID_ATTR_TRANSFORM );
266 	}
267 
268 	if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
269 	{
270 		SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
271 		pView->GetAttributes( aAttrs );
272 		if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
273 		{
274 			sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
275 			rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
276 		}
277 	}
278 
279 	svx::ExtrusionBar::getState( pView, rSet );
280 	svx::FontworkBar::getState( pView, rSet );
281 }
282 
283 //
284 //			Attribute fuer Drawing-Objekte
285 //
286 
287 void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
288 {
289 	Point		aMousePos	= pViewData->GetMousePosPixel();
290 	Window* 	pWindow		= pViewData->GetActiveWin();
291 	ScDrawView* pDrView		= pViewData->GetScDrawView();
292 	Point		aPos	 	= pWindow->PixelToLogic(aMousePos);
293 	sal_Bool		bHasMarked	= pDrView->AreObjectsMarked();
294 
295 	if( bHasMarked )
296 	{
297 		rSet.Put( pDrView->GetAttrFromMarked(sal_False) );
298 
299 		// Wenn die View selektierte Objekte besitzt, muessen entspr. Items
300 		// von SFX_ITEM_DEFAULT (_ON) auf SFX_ITEM_DISABLED geaendert werden
301 
302 		SfxWhichIter aIter( rSet, XATTR_LINE_FIRST, XATTR_FILL_LAST );
303 		sal_uInt16 nWhich = aIter.FirstWhich();
304 		while( nWhich )
305 		{
306 			if( SFX_ITEM_DEFAULT == rSet.GetItemState( nWhich ) )
307 				rSet.DisableItem( nWhich );
308 
309 			nWhich = aIter.NextWhich();
310 		}
311 	}
312 	else
313 		rSet.Put( pDrView->GetDefaultAttr() );
314 
315     SdrPageView* pPV = pDrView->GetSdrPageView();
316     if ( pPV )
317     {
318         // #i52073# when a sheet with an active OLE object is deleted,
319         // the slot state is queried without an active page view
320 
321         //  Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
322 
323         // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
324         // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
325 
326         sal_Bool bActionItem = sal_False;
327         if ( pDrView->IsAction() )              // action rectangle
328         {
329             Rectangle aRect;
330             pDrView->TakeActionRect( aRect );
331             if ( !aRect.IsEmpty() )
332             {
333                 pPV->LogicToPagePos(aRect);
334                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
335                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
336                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
337                 bActionItem = sal_True;
338             }
339         }
340         if ( !bActionItem )
341         {
342             if ( pDrView->AreObjectsMarked() )      // selected objects
343             {
344                 Rectangle aRect = pDrView->GetAllMarkedRect();
345                 pPV->LogicToPagePos(aRect);
346                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
347                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
348                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
349             }
350             else                                // mouse position
351             {
352                 // aPos is initialized above
353                 pPV->LogicToPagePos(aPos);
354                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
355                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
356             }
357         }
358     }
359 }
360 
361 void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
362 {
363 	//	Dialoge fuer Draw-Attribute disablen, wenn noetig
364 
365 	ScDrawView* pDrView	= pViewData->GetScDrawView();
366 	SfxItemSet aViewSet = pDrView->GetAttrFromMarked(sal_False);
367 
368 	if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
369 	{
370 		rSet.DisableItem( SID_ATTRIBUTES_LINE );
371 		rSet.DisableItem( SID_ATTR_LINEEND_STYLE );		// Tbx-Controller
372 	}
373 
374 	if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
375 		rSet.DisableItem( SID_ATTRIBUTES_AREA );
376 }
377 
378 sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
379 {
380 	sal_Bool bResult=sal_True;
381 	sal_uLong nCount = rMark.GetMarkCount();
382 	for (sal_uLong i=0; i<nCount; i++)
383 	{
384 		SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
385 		if ( !pObj->ISA(SdrUnoObj) )
386 		{
387 			if(nLayerNo!=pObj->GetLayer())
388 			{
389 				bResult=sal_False;
390 				break;
391 			}
392 		}
393 	}
394 	return bResult;
395 }
396 
397 void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
398 {
399   	ScDrawView* pView = pViewData->GetScDrawView();
400   	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
401 
402   	if( rMarkList.GetMark(0) != 0 )
403   	{
404   		SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
405   		rSet.Put(aNewAttr, sal_False);
406   	}
407 }
408