xref: /aoo42x/main/sc/source/ui/drawfunc/drawsh2.cxx (revision 2a3f8a0e)
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 #include <svx/sidebar/SelectionChangeHandler.hxx>
45 #include <svx/sidebar/SelectionAnalyzer.hxx>
46 #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
47 
48 #include "drawsh.hxx"
49 #include "drawview.hxx"
50 #include "viewdata.hxx"
51 #include "sc.hrc"
52 #include "tabvwsh.hxx"
53 #include "document.hxx"
54 #include "drwlayer.hxx"
55 #include "userdat.hxx"
56 #include <svx/svdoole2.hxx>
57 #include <svx/svdocapt.hxx>
58 
59 #include <boost/bind.hpp>
60 
61 
62 sal_uInt16 ScGetFontWorkId();		// in drtxtob
63 
64 using namespace com::sun::star;
65 
66 
67 //------------------------------------------------------------------
68 
ScDrawShell(ScViewData * pData)69 ScDrawShell::ScDrawShell( ScViewData* pData ) :
70 	SfxShell(pData->GetViewShell()),
71 	pViewData( pData ),
72     mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
73             ::boost::bind(&ScDrawShell::GetSidebarContextName, this),
74             GetFrame()->GetFrame().GetController(),
75             sfx2::sidebar::EnumContext::Context_Cell))
76 {
77 	SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
78     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
79     SetUndoManager( pMgr );
80     if ( !pViewData->GetDocument()->IsUndoEnabled() )
81     {
82         pMgr->SetMaxUndoActionCount( 0 );
83     }
84 	SetHelpId( HID_SCSHELL_DRAWSH );
85 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Drawing")));
86 
87     mpSelectionChangeHandler->Connect();
88 }
89 
~ScDrawShell()90 ScDrawShell::~ScDrawShell()
91 {
92     mpSelectionChangeHandler->Disconnect();
93 }
94 
GetState(SfxItemSet & rSet)95 void ScDrawShell::GetState( SfxItemSet& rSet )			// Zustaende / Toggles
96 {
97 	ScDrawView* pView	 = pViewData->GetScDrawView();
98 	SdrDragMode eMode	 = pView->GetDragMode();
99 
100 	rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
101 	rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
102 	rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
103 
104 	sal_uInt16 nFWId = ScGetFontWorkId();
105 	SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
106 	rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
107 
108         // Notes always default to Page anchor.
109 	bool bDisableAnchor = false;
110 	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
111 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
112 	if ( nMarkCount == 1 )
113 	{
114         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
115         if( ScDrawLayer::IsNoteCaption( pObj ) )
116 	    {
117             bDisableAnchor = true;
118             rSet.DisableItem( SID_ANCHOR_PAGE );
119             rSet.DisableItem( SID_ANCHOR_CELL );
120 	    }
121 	}
122 
123 	if ( !bDisableAnchor )
124 	{
125 	    switch( pView->GetAnchor() )
126 	    {
127 		case SCA_PAGE:
128 	        rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_True ) );
129 	        rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_False ) );
130 		break;
131 
132 		case SCA_CELL:
133 		rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_False ) );
134 		rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_True ) );
135 		break;
136 
137 		default:
138 		rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_False ) );
139 		rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_False ) );
140 		break;
141 	    }
142 	}
143 }
144 
GetDrawFuncState(SfxItemSet & rSet)145 void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )		// Funktionen disablen
146 {
147 	ScDrawView* pView = pViewData->GetScDrawView();
148 
149 	//	#111711# call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
150 	//	is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
151 	if (!pView->IsMirrorAllowed(sal_True,sal_True))
152 	{
153 		rSet.DisableItem( SID_MIRROR_HORIZONTAL );
154 		rSet.DisableItem( SID_MIRROR_VERTICAL );
155 		rSet.DisableItem( SID_FLIP_HORIZONTAL );
156 		rSet.DisableItem( SID_FLIP_VERTICAL );
157 	}
158 
159 	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
160 	sal_uLong nMarkCount = rMarkList.GetMarkCount();
161 
162 	if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
163 		rSet.DisableItem( SID_GROUP );
164 	if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
165 		rSet.DisableItem( SID_UNGROUP );
166 	if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
167 		rSet.DisableItem( SID_ENTER_GROUP );
168 	if ( !pView->IsGroupEntered() )
169 		rSet.DisableItem( SID_LEAVE_GROUP );
170 
171 	if ( nMarkCount <= 1 )						// nichts oder nur ein Objekt selektiert
172 	{
173 			//	Ausrichtung
174 		rSet.DisableItem( SID_OBJECT_ALIGN_LEFT );		// keine Ausrichtung an der Seite
175 		rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
176 		rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
177 		rSet.DisableItem( SID_OBJECT_ALIGN_UP );
178 		rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
179 		rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
180 
181         // pseudo slots for Format menu
182         rSet.DisableItem( SID_ALIGN_ANY_LEFT );
183         rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
184         rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
185         rSet.DisableItem( SID_ALIGN_ANY_TOP );
186         rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
187         rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
188 	}
189 
190     // do not change layer of form controls
191     // #158385# #i83729# do not change layer of cell notes (on internal layer)
192 	if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
193 	{
194 		rSet.DisableItem( SID_OBJECT_HEAVEN );
195 		rSet.DisableItem( SID_OBJECT_HELL );
196 	}
197 	else
198 	{
199 		if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
200 		{
201 			rSet.DisableItem( SID_OBJECT_HEAVEN );
202 		}
203 		else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
204 		{
205 			rSet.DisableItem( SID_OBJECT_HELL );
206 		}
207 	}
208 
209 	sal_Bool bCanRename = sal_False;
210     if ( nMarkCount > 1 )
211     {
212 #ifdef ISSUE66550_HLINK_FOR_SHAPES
213         // no hypelink options for a selected group
214         rSet.DisableItem( SID_DRAW_HLINK_EDIT );
215         rSet.DisableItem( SID_DRAW_HLINK_DELETE );
216         rSet.DisableItem( SID_OPEN_HYPERLINK );
217 #endif
218     }
219     else if ( nMarkCount == 1 )
220 	{
221         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
222 #ifdef ISSUE66550_HLINK_FOR_SHAPES
223         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
224         if ( !pInfo || (pInfo->GetHlink().getLength() == 0) )
225         {
226             rSet.DisableItem( SID_DRAW_HLINK_DELETE );
227             rSet.DisableItem( SID_OPEN_HYPERLINK );
228         }
229 #endif
230         SdrLayerID nLayerID = pObj->GetLayer();
231         if ( nLayerID != SC_LAYER_INTERN )
232             bCanRename = sal_True;                          // #i51351# anything except internal objects can be renamed
233 
234         // #91929#; don't show original size entry if not possible
235         sal_uInt16 nObjType = pObj->GetObjIdentifier();
236         if ( nObjType == OBJ_OLE2 )
237         {
238             SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
239             if (pOleObj->GetObjRef().is() &&
240                 ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
241                 //TODO/LATER: why different slots in Draw and Calc?
242                 rSet.DisableItem(SID_ORIGINALSIZE);
243         }
244         else if ( nObjType == OBJ_CAPTION )
245         {
246             if ( nLayerID == SC_LAYER_INTERN )
247             {
248                 // SdrCaptionObj() Notes cannot be cut/copy in isolation from
249                 // their cells.
250                 rSet.DisableItem( SID_CUT );
251                 rSet.DisableItem( SID_COPY );
252                 // Notes always default to Page anchor.
253                 rSet.DisableItem( SID_ANCHOR_TOGGLE );
254             }
255         }
256 	}
257 	if ( !bCanRename )
258 	{
259 		// #i68101#
260 		rSet.DisableItem( SID_RENAME_OBJECT );
261 		rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
262 	}
263 
264 	if ( !nMarkCount )							// nichts selektiert
265 	{
266 			//	Anordnung
267 		rSet.DisableItem( SID_FRAME_UP );
268 		rSet.DisableItem( SID_FRAME_DOWN );
269 		rSet.DisableItem( SID_FRAME_TO_TOP );
270 		rSet.DisableItem( SID_FRAME_TO_BOTTOM );
271 			//	Clipboard / loeschen
272 		rSet.DisableItem( SID_DELETE );
273 		rSet.DisableItem( SID_DELETE_CONTENTS );
274 		rSet.DisableItem( SID_CUT );
275 		rSet.DisableItem( SID_COPY );
276 			//	sonstiges
277 		rSet.DisableItem( SID_ANCHOR_TOGGLE );
278 		rSet.DisableItem( SID_ORIGINALSIZE );
279 		rSet.DisableItem( SID_ATTR_TRANSFORM );
280 	}
281 
282 	if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
283 	{
284 		SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
285 		pView->GetAttributes( aAttrs );
286 		if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
287 		{
288 			sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
289 			rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
290 		}
291 	}
292 
293 	svx::ExtrusionBar::getState( pView, rSet );
294 	svx::FontworkBar::getState( pView, rSet );
295 }
296 
297 //
298 //			Attribute fuer Drawing-Objekte
299 //
300 
GetDrawAttrState(SfxItemSet & rSet)301 void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
302 {
303 	Point		aMousePos	= pViewData->GetMousePosPixel();
304 	Window* 	pWindow		= pViewData->GetActiveWin();
305 	ScDrawView* pDrView		= pViewData->GetScDrawView();
306 	Point		aPos	 	= pWindow->PixelToLogic(aMousePos);
307 	sal_Bool		bHasMarked	= pDrView->AreObjectsMarked();
308 
309 	if( bHasMarked )
310 	{
311 		rSet.Put( pDrView->GetAttrFromMarked(sal_False), false );
312 	}
313 	else
314     {
315 		rSet.Put( pDrView->GetDefaultAttr() );
316     }
317 
318     SdrPageView* pPV = pDrView->GetSdrPageView();
319     if ( pPV )
320     {
321         // #i52073# when a sheet with an active OLE object is deleted,
322         // the slot state is queried without an active page view
323 
324         //  Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
325 
326         // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
327         // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
328 
329         sal_Bool bActionItem = sal_False;
330         if ( pDrView->IsAction() )              // action rectangle
331         {
332             Rectangle aRect;
333             pDrView->TakeActionRect( aRect );
334             if ( !aRect.IsEmpty() )
335             {
336                 pPV->LogicToPagePos(aRect);
337                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
338                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
339                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
340                 bActionItem = sal_True;
341             }
342         }
343         if ( !bActionItem )
344         {
345             if ( pDrView->AreObjectsMarked() )      // selected objects
346             {
347                 Rectangle aRect = pDrView->GetAllMarkedRect();
348                 pPV->LogicToPagePos(aRect);
349                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
350                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
351                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
352             }
353             else                                // mouse position
354             {
355                 // aPos is initialized above
356                 pPV->LogicToPagePos(aPos);
357                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
358                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
359             }
360         }
361     }
362 }
363 
GetAttrFuncState(SfxItemSet & rSet)364 void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
365 {
366 	//	Dialoge fuer Draw-Attribute disablen, wenn noetig
367 
368 	ScDrawView* pDrView	= pViewData->GetScDrawView();
369 	SfxItemSet aViewSet = pDrView->GetAttrFromMarked(sal_False);
370 
371 	if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
372 	{
373 		rSet.DisableItem( SID_ATTRIBUTES_LINE );
374 		rSet.DisableItem( SID_ATTR_LINEEND_STYLE );		// Tbx-Controller
375 	}
376 
377 	if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
378 		rSet.DisableItem( SID_ATTRIBUTES_AREA );
379 }
380 
AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList & rMark)381 sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
382 {
383 	sal_Bool bResult=sal_True;
384 	sal_uLong nCount = rMark.GetMarkCount();
385 	for (sal_uLong i=0; i<nCount; i++)
386 	{
387 		SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
388 		if ( !pObj->ISA(SdrUnoObj) )
389 		{
390 			if(nLayerNo!=pObj->GetLayer())
391 			{
392 				bResult=sal_False;
393 				break;
394 			}
395 		}
396 	}
397 	return bResult;
398 }
399 
GetDrawAttrStateForIFBX(SfxItemSet & rSet)400 void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
401 {
402   	ScDrawView* pView = pViewData->GetScDrawView();
403   	const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
404 
405   	if( rMarkList.GetMark(0) != 0 )
406   	{
407   		SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
408   		rSet.Put(aNewAttr, sal_False);
409   	}
410 }
411 
412 
413 
414 
Activate(const sal_Bool bMDI)415 void ScDrawShell::Activate (const sal_Bool bMDI)
416 {
417     (void)bMDI;
418 
419     ContextChangeEventMultiplexer::NotifyContextChange(
420         GetFrame()->GetFrame().GetController(),
421         ::sfx2::sidebar::EnumContext::GetContextEnum(
422             GetSidebarContextName()));
423 }
424 
425 
426 
427 
GetSidebarContextName(void)428 ::rtl::OUString ScDrawShell::GetSidebarContextName (void)
429 {
430     return sfx2::sidebar::EnumContext::GetContextName(
431         ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
432             GetDrawView()->GetMarkedObjectList()));
433 }
434