xref: /aoo41x/main/sc/source/ui/drawfunc/drawsh2.cxx (revision b3f79822)
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 	}
142 
143 	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
144 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
145 
146 	if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
147 		rSet.DisableItem( SID_GROUP );
148 	if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
149 		rSet.DisableItem( SID_UNGROUP );
150 	if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
151 		rSet.DisableItem( SID_ENTER_GROUP );
152 	if ( !pView->IsGroupEntered() )
153 		rSet.DisableItem( SID_LEAVE_GROUP );
154 
155 	if ( nMarkCount <= 1 )						// nichts oder nur ein Objekt selektiert
156 	{
157 			//	Ausrichtung
158 		rSet.DisableItem( SID_OBJECT_ALIGN_LEFT );		// keine Ausrichtung an der Seite
159 		rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
160 		rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
161 		rSet.DisableItem( SID_OBJECT_ALIGN_UP );
162 		rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
163 		rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
164 
165         // pseudo slots for Format menu
166         rSet.DisableItem( SID_ALIGN_ANY_LEFT );
167         rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
168         rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
169         rSet.DisableItem( SID_ALIGN_ANY_TOP );
170         rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
171         rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
172 	}
173 
174     // do not change layer of form controls
175     // #158385# #i83729# do not change layer of cell notes (on internal layer)
176 	if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
177 	{
178 		rSet.DisableItem( SID_OBJECT_HEAVEN );
179 		rSet.DisableItem( SID_OBJECT_HELL );
180 	}
181 	else
182 	{
183 		if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
184 		{
185 			rSet.DisableItem( SID_OBJECT_HEAVEN );
186 		}
187 		else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
188 		{
189 			rSet.DisableItem( SID_OBJECT_HELL );
190 		}
191 	}
192 
193 	sal_Bool bCanRename = sal_False;
194     if ( nMarkCount > 1 )
195     {
196 #ifdef ISSUE66550_HLINK_FOR_SHAPES
197         // no hypelink options for a selected group
198         rSet.DisableItem( SID_DRAW_HLINK_EDIT );
199         rSet.DisableItem( SID_DRAW_HLINK_DELETE );
200         rSet.DisableItem( SID_OPEN_HYPERLINK );
201 #endif
202     }
203     else if ( nMarkCount == 1 )
204 	{
205         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
206 #ifdef ISSUE66550_HLINK_FOR_SHAPES
207         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
208         if ( !pInfo || (pInfo->GetHlink().getLength() == 0) )
209         {
210             rSet.DisableItem( SID_DRAW_HLINK_DELETE );
211             rSet.DisableItem( SID_OPEN_HYPERLINK );
212         }
213 #endif
214         SdrLayerID nLayerID = pObj->GetLayer();
215         if ( nLayerID != SC_LAYER_INTERN )
216             bCanRename = sal_True;                          // #i51351# anything except internal objects can be renamed
217 
218         // #91929#; don't show original size entry if not possible
219         sal_uInt16 nObjType = pObj->GetObjIdentifier();
220         if ( nObjType == OBJ_OLE2 )
221         {
222             SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
223             if (pOleObj->GetObjRef().is() &&
224                 ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
225                 //TODO/LATER: why different slots in Draw and Calc?
226                 rSet.DisableItem(SID_ORIGINALSIZE);
227         }
228         else if ( nObjType == OBJ_CAPTION )
229         {
230             if ( nLayerID == SC_LAYER_INTERN )
231             {
232                 // SdrCaptionObj() Notes cannot be cut/copy in isolation from
233                 // their cells.
234                 rSet.DisableItem( SID_CUT );
235                 rSet.DisableItem( SID_COPY );
236                 // Notes always default to Page anchor.
237                 rSet.DisableItem( SID_ANCHOR_TOGGLE );
238             }
239         }
240 	}
241 	if ( !bCanRename )
242 	{
243 		// #i68101#
244 		rSet.DisableItem( SID_RENAME_OBJECT );
245 		rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
246 	}
247 
248 	if ( !nMarkCount )							// nichts selektiert
249 	{
250 			//	Anordnung
251 		rSet.DisableItem( SID_FRAME_UP );
252 		rSet.DisableItem( SID_FRAME_DOWN );
253 		rSet.DisableItem( SID_FRAME_TO_TOP );
254 		rSet.DisableItem( SID_FRAME_TO_BOTTOM );
255 			//	Clipboard / loeschen
256 		rSet.DisableItem( SID_DELETE );
257 		rSet.DisableItem( SID_DELETE_CONTENTS );
258 		rSet.DisableItem( SID_CUT );
259 		rSet.DisableItem( SID_COPY );
260 			//	sonstiges
261 		rSet.DisableItem( SID_ANCHOR_TOGGLE );
262 		rSet.DisableItem( SID_ORIGINALSIZE );
263 		rSet.DisableItem( SID_ATTR_TRANSFORM );
264 	}
265 
266 	if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
267 	{
268 		SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
269 		pView->GetAttributes( aAttrs );
270 		if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
271 		{
272 			sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
273 			rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
274 		}
275 	}
276 
277 	svx::ExtrusionBar::getState( pView, rSet );
278 	svx::FontworkBar::getState( pView, rSet );
279 }
280 
281 //
282 //			Attribute fuer Drawing-Objekte
283 //
284 
285 void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
286 {
287 	Point		aMousePos	= pViewData->GetMousePosPixel();
288 	Window* 	pWindow		= pViewData->GetActiveWin();
289 	ScDrawView* pDrView		= pViewData->GetScDrawView();
290 	Point		aPos	 	= pWindow->PixelToLogic(aMousePos);
291 	sal_Bool		bHasMarked	= pDrView->AreObjectsMarked();
292 
293 	if( bHasMarked )
294 	{
295 		rSet.Put( pDrView->GetAttrFromMarked(sal_False) );
296 
297 		// Wenn die View selektierte Objekte besitzt, muessen entspr. Items
298 		// von SFX_ITEM_DEFAULT (_ON) auf SFX_ITEM_DISABLED geaendert werden
299 
300 		SfxWhichIter aIter( rSet, XATTR_LINE_FIRST, XATTR_FILL_LAST );
301 		sal_uInt16 nWhich = aIter.FirstWhich();
302 		while( nWhich )
303 		{
304 			if( SFX_ITEM_DEFAULT == rSet.GetItemState( nWhich ) )
305 				rSet.DisableItem( nWhich );
306 
307 			nWhich = aIter.NextWhich();
308 		}
309 	}
310 	else
311 		rSet.Put( pDrView->GetDefaultAttr() );
312 
313     SdrPageView* pPV = pDrView->GetSdrPageView();
314     if ( pPV )
315     {
316         // #i52073# when a sheet with an active OLE object is deleted,
317         // the slot state is queried without an active page view
318 
319         //  Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
320 
321         // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
322         // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
323 
324         sal_Bool bActionItem = sal_False;
325         if ( pDrView->IsAction() )              // action rectangle
326         {
327             Rectangle aRect;
328             pDrView->TakeActionRect( aRect );
329             if ( !aRect.IsEmpty() )
330             {
331                 pPV->LogicToPagePos(aRect);
332                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
333                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
334                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
335                 bActionItem = sal_True;
336             }
337         }
338         if ( !bActionItem )
339         {
340             if ( pDrView->AreObjectsMarked() )      // selected objects
341             {
342                 Rectangle aRect = pDrView->GetAllMarkedRect();
343                 pPV->LogicToPagePos(aRect);
344                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
345                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
346                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
347             }
348             else                                // mouse position
349             {
350                 // aPos is initialized above
351                 pPV->LogicToPagePos(aPos);
352                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
353                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
354             }
355         }
356     }
357 }
358 
359 void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
360 {
361 	//	Dialoge fuer Draw-Attribute disablen, wenn noetig
362 
363 	ScDrawView* pDrView	= pViewData->GetScDrawView();
364 	SfxItemSet aViewSet = pDrView->GetAttrFromMarked(sal_False);
365 
366 	if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
367 	{
368 		rSet.DisableItem( SID_ATTRIBUTES_LINE );
369 		rSet.DisableItem( SID_ATTR_LINEEND_STYLE );		// Tbx-Controller
370 	}
371 
372 	if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
373 		rSet.DisableItem( SID_ATTRIBUTES_AREA );
374 }
375 
376 sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
377 {
378 	sal_Bool bResult=sal_True;
379 	sal_uLong nCount = rMark.GetMarkCount();
380 	for (sal_uLong i=0; i<nCount; i++)
381 	{
382 		SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
383 		if ( !pObj->ISA(SdrUnoObj) )
384 		{
385 			if(nLayerNo!=pObj->GetLayer())
386 			{
387 				bResult=sal_False;
388 				break;
389 			}
390 		}
391 	}
392 	return bResult;
393 }
394 
395 
396