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