Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / drawsh2.cxx
blob94c685275957d8c634d491e6153581fc623b94b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/EmbedMisc.hpp>
22 #include "scitems.hxx"
23 #include <editeng/eeitem.hxx>
24 #include <editeng/sizeitem.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <svx/xdef.hxx>
27 #include <sfx2/app.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svl/ptitem.hxx>
31 #include <svl/whiter.hxx>
32 #include <svx/svdobj.hxx>
33 #include <svx/svdouno.hxx>
34 #include <svx/extrusionbar.hxx>
35 #include <svx/fontworkbar.hxx>
36 #include <svx/sidebar/SelectionChangeHandler.hxx>
37 #include <svx/sidebar/SelectionAnalyzer.hxx>
38 #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
40 #include "drawsh.hxx"
41 #include "drawview.hxx"
42 #include "viewdata.hxx"
43 #include "sc.hrc"
44 #include "tabvwsh.hxx"
45 #include "document.hxx"
46 #include "drwlayer.hxx"
47 #include "userdat.hxx"
48 #include <svx/svdoole2.hxx>
49 #include <svx/svdocapt.hxx>
51 #include <boost/bind.hpp>
54 sal_uInt16 ScGetFontWorkId(); // in drtxtob
56 using namespace com::sun::star;
59 //------------------------------------------------------------------
61 ScDrawShell::ScDrawShell( ScViewData* pData ) :
62 SfxShell(pData->GetViewShell()),
63 pViewData( pData ),
64 mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
65 ::boost::bind(&ScDrawShell::GetSidebarContextName, this),
66 GetFrame()->GetFrame().GetController(),
67 sfx2::sidebar::EnumContext::Context_Cell))
69 SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
70 ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
71 SetUndoManager( pMgr );
72 if ( !pViewData->GetDocument()->IsUndoEnabled() )
74 pMgr->SetMaxUndoActionCount( 0 );
76 SetHelpId( HID_SCSHELL_DRAWSH );
77 SetName(OUString("Drawing"));
79 mpSelectionChangeHandler->Connect();
82 ScDrawShell::~ScDrawShell()
84 mpSelectionChangeHandler->Disconnect();
87 void ScDrawShell::GetState( SfxItemSet& rSet ) // Zustaende / Toggles
89 ScDrawView* pView = pViewData->GetScDrawView();
90 SdrDragMode eMode = pView->GetDragMode();
92 rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
93 rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
94 rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
96 sal_uInt16 nFWId = ScGetFontWorkId();
97 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
98 rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
100 // Notes always default to Page anchor.
101 bool bDisableAnchor = false;
102 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
103 sal_uLong nMarkCount = rMarkList.GetMarkCount();
104 if ( nMarkCount == 1 )
106 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
107 if( ScDrawLayer::IsNoteCaption( pObj ) )
109 bDisableAnchor = true;
110 rSet.DisableItem( SID_ANCHOR_PAGE );
111 rSet.DisableItem( SID_ANCHOR_CELL );
115 if ( !bDisableAnchor )
117 switch( pView->GetAnchorType() )
119 case SCA_PAGE:
120 rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_True ) );
121 rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
122 break;
124 case SCA_CELL:
125 rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
126 rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_True ) );
127 break;
129 default:
130 rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
131 rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
132 break;
137 void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // Funktionen disablen
139 ScDrawView* pView = pViewData->GetScDrawView();
141 // call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
142 // is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
143 if (!pView->IsMirrorAllowed(sal_True,sal_True))
145 rSet.DisableItem( SID_MIRROR_HORIZONTAL );
146 rSet.DisableItem( SID_MIRROR_VERTICAL );
147 rSet.DisableItem( SID_FLIP_HORIZONTAL );
148 rSet.DisableItem( SID_FLIP_VERTICAL );
151 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
152 sal_uLong nMarkCount = rMarkList.GetMarkCount();
154 if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
155 rSet.DisableItem( SID_GROUP );
156 if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
157 rSet.DisableItem( SID_UNGROUP );
158 if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
159 rSet.DisableItem( SID_ENTER_GROUP );
160 if ( !pView->IsGroupEntered() )
161 rSet.DisableItem( SID_LEAVE_GROUP );
163 if ( nMarkCount <= 1 ) // nichts oder nur ein Objekt selektiert
165 // Ausrichtung
166 rSet.DisableItem( SID_OBJECT_ALIGN_LEFT ); // keine Ausrichtung an der Seite
167 rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
168 rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
169 rSet.DisableItem( SID_OBJECT_ALIGN_UP );
170 rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
171 rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
173 // pseudo slots for Format menu
174 rSet.DisableItem( SID_ALIGN_ANY_LEFT );
175 rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
176 rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
177 rSet.DisableItem( SID_ALIGN_ANY_TOP );
178 rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
179 rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
182 // do not change layer of form controls
183 // #i83729# do not change layer of cell notes (on internal layer)
184 if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
186 rSet.DisableItem( SID_OBJECT_HEAVEN );
187 rSet.DisableItem( SID_OBJECT_HELL );
189 else
191 if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
193 rSet.DisableItem( SID_OBJECT_HEAVEN );
195 else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
197 rSet.DisableItem( SID_OBJECT_HELL );
201 sal_Bool bCanRename = false;
202 if ( nMarkCount > 1 )
204 // no hypelink options for a selected group
205 rSet.DisableItem( SID_DRAW_HLINK_EDIT );
206 rSet.DisableItem( SID_DRAW_HLINK_DELETE );
207 rSet.DisableItem( SID_OPEN_HYPERLINK );
209 else if ( nMarkCount == 1 )
211 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
212 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
213 if ( !pInfo || pInfo->GetHlink().isEmpty() )
215 rSet.DisableItem( SID_DRAW_HLINK_DELETE );
216 rSet.DisableItem( SID_OPEN_HYPERLINK );
218 SdrLayerID nLayerID = pObj->GetLayer();
219 if ( nLayerID != SC_LAYER_INTERN )
220 bCanRename = sal_True; // #i51351# anything except internal objects can be renamed
222 // #91929#; don't show original size entry if not possible
223 sal_uInt16 nObjType = pObj->GetObjIdentifier();
224 if ( nObjType == OBJ_OLE2 )
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);
232 else if ( nObjType == OBJ_CAPTION )
234 if ( nLayerID == SC_LAYER_INTERN )
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 );
245 if ( !bCanRename )
247 // #i68101#
248 rSet.DisableItem( SID_RENAME_OBJECT );
249 rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
252 if ( !nMarkCount ) // nichts selektiert
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 );
270 if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
272 SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
273 pView->GetAttributes( aAttrs );
274 if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
276 sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
277 rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
281 svx::ExtrusionBar::getState( pView, rSet );
282 svx::FontworkBar::getState( pView, rSet );
286 // Attribute fuer Drawing-Objekte
289 void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
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();
297 if( bHasMarked )
299 rSet.Put( pDrView->GetAttrFromMarked(false), false );
301 else
303 rSet.Put( pDrView->GetDefaultAttr() );
306 SdrPageView* pPV = pDrView->GetSdrPageView();
307 if ( pPV )
309 // #i52073# when a sheet with an active OLE object is deleted,
310 // the slot state is queried without an active page view
312 // Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
314 // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
315 // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
317 sal_Bool bActionItem = false;
318 if ( pDrView->IsAction() ) // action rectangle
320 Rectangle aRect;
321 pDrView->TakeActionRect( aRect );
322 if ( !aRect.IsEmpty() )
324 pPV->LogicToPagePos(aRect);
325 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
326 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
327 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
328 bActionItem = sal_True;
331 if ( !bActionItem )
333 if ( pDrView->AreObjectsMarked() ) // selected objects
335 Rectangle aRect = pDrView->GetAllMarkedRect();
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 ) );
341 else // mouse position
343 // aPos is initialized above
344 pPV->LogicToPagePos(aPos);
345 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
346 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
352 void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
354 // Dialoge fuer Draw-Attribute disablen, wenn noetig
356 ScDrawView* pDrView = pViewData->GetScDrawView();
357 SfxItemSet aViewSet = pDrView->GetAttrFromMarked(false);
359 if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
361 rSet.DisableItem( SID_ATTRIBUTES_LINE );
362 rSet.DisableItem( SID_ATTR_LINEEND_STYLE ); // Tbx-Controller
365 if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
366 rSet.DisableItem( SID_ATTRIBUTES_AREA );
369 sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
371 sal_Bool bResult=sal_True;
372 sal_uLong nCount = rMark.GetMarkCount();
373 for (sal_uLong i=0; i<nCount; i++)
375 SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
376 if ( !pObj->ISA(SdrUnoObj) )
378 if(nLayerNo!=pObj->GetLayer())
380 bResult=false;
381 break;
385 return bResult;
388 void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
390 ScDrawView* pView = pViewData->GetScDrawView();
391 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
393 if( rMarkList.GetMark(0) != 0 )
395 SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
396 rSet.Put(aNewAttr, sal_False);
403 void ScDrawShell::Activate (const sal_Bool bMDI)
405 (void)bMDI;
407 ContextChangeEventMultiplexer::NotifyContextChange(
408 GetFrame()->GetFrame().GetController(),
409 ::sfx2::sidebar::EnumContext::GetContextEnum(
410 GetSidebarContextName()));
416 ::rtl::OUString ScDrawShell::GetSidebarContextName (void)
418 return sfx2::sidebar::EnumContext::GetContextName(
419 ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
420 GetDrawView()->GetMarkedObjectList()));
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */