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