1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
41 #include "drawview.hxx"
42 #include "viewdata.hxx"
44 #include "tabvwsh.hxx"
45 #include "document.hxx"
46 #include "drwlayer.hxx"
47 #include "userdat.hxx"
48 #include <gridwin.hxx>
49 #include <svx/svdoole2.hxx>
50 #include <svx/svdocapt.hxx>
52 #include <boost/bind.hpp>
55 sal_uInt16
ScGetFontWorkId(); // in drtxtob
57 using namespace com::sun::star
;
60 ScDrawShell::ScDrawShell( ScViewData
* pData
) :
61 SfxShell(pData
->GetViewShell()),
63 mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
64 ::boost::bind(&ScDrawShell::GetSidebarContextName
, this),
65 GetFrame()->GetFrame().GetController(),
66 sfx2::sidebar::EnumContext::Context_Cell
))
68 SetPool( &pViewData
->GetScDrawView()->GetModel()->GetItemPool() );
69 ::svl::IUndoManager
* pMgr
= pViewData
->GetSfxDocShell()->GetUndoManager();
70 SetUndoManager( pMgr
);
71 if ( !pViewData
->GetDocument()->IsUndoEnabled() )
73 pMgr
->SetMaxUndoActionCount( 0 );
75 SetHelpId( HID_SCSHELL_DRAWSH
);
76 SetName(OUString("Drawing"));
78 mpSelectionChangeHandler
->Connect();
81 ScDrawShell::~ScDrawShell()
83 mpSelectionChangeHandler
->Disconnect();
86 void ScDrawShell::GetState( SfxItemSet
& rSet
) // Zustaende / Toggles
88 ScDrawView
* pView
= pViewData
->GetScDrawView();
89 SdrDragMode eMode
= pView
->GetDragMode();
91 rSet
.Put( SfxBoolItem( SID_OBJECT_ROTATE
, eMode
== SDRDRAG_ROTATE
) );
92 rSet
.Put( SfxBoolItem( SID_OBJECT_MIRROR
, eMode
== SDRDRAG_MIRROR
) );
93 rSet
.Put( SfxBoolItem( SID_BEZIER_EDIT
, !pView
->IsFrameDragSingles() ) );
95 sal_uInt16 nFWId
= ScGetFontWorkId();
96 SfxViewFrame
* pViewFrm
= pViewData
->GetViewShell()->GetViewFrame();
97 rSet
.Put(SfxBoolItem(SID_FONTWORK
, pViewFrm
->HasChildWindow(nFWId
)));
99 // Notes always default to Page anchor.
100 bool bDisableAnchor
= false;
101 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
102 sal_uLong nMarkCount
= rMarkList
.GetMarkCount();
103 if ( nMarkCount
== 1 )
105 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
106 if( ScDrawLayer::IsNoteCaption( pObj
) )
108 bDisableAnchor
= true;
109 rSet
.DisableItem( SID_ANCHOR_PAGE
);
110 rSet
.DisableItem( SID_ANCHOR_CELL
);
114 if ( !bDisableAnchor
)
116 switch( pView
->GetAnchorType() )
119 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, true ) );
120 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, false ) );
124 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, false ) );
125 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, true ) );
129 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, false ) );
130 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, false ) );
136 void ScDrawShell::GetDrawFuncState( SfxItemSet
& rSet
) // Funktionen disablen
138 ScDrawView
* pView
= pViewData
->GetScDrawView();
140 // call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
141 // is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
142 if (!pView
->IsMirrorAllowed(true,true))
144 rSet
.DisableItem( SID_MIRROR_HORIZONTAL
);
145 rSet
.DisableItem( SID_MIRROR_VERTICAL
);
146 rSet
.DisableItem( SID_FLIP_HORIZONTAL
);
147 rSet
.DisableItem( SID_FLIP_VERTICAL
);
150 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
151 sal_uLong nMarkCount
= rMarkList
.GetMarkCount();
153 if ( nMarkCount
<= 1 || !pView
->IsGroupPossible() )
154 rSet
.DisableItem( SID_GROUP
);
155 if ( nMarkCount
== 0 || !pView
->IsUnGroupPossible() )
156 rSet
.DisableItem( SID_UNGROUP
);
157 if ( nMarkCount
!= 1 || !pView
->IsGroupEnterPossible() )
158 rSet
.DisableItem( SID_ENTER_GROUP
);
159 if ( !pView
->IsGroupEntered() )
160 rSet
.DisableItem( SID_LEAVE_GROUP
);
162 if ( nMarkCount
<= 1 ) // nichts oder nur ein Objekt selektiert
165 rSet
.DisableItem( SID_OBJECT_ALIGN_LEFT
); // keine Ausrichtung an der Seite
166 rSet
.DisableItem( SID_OBJECT_ALIGN_CENTER
);
167 rSet
.DisableItem( SID_OBJECT_ALIGN_RIGHT
);
168 rSet
.DisableItem( SID_OBJECT_ALIGN_UP
);
169 rSet
.DisableItem( SID_OBJECT_ALIGN_MIDDLE
);
170 rSet
.DisableItem( SID_OBJECT_ALIGN_DOWN
);
172 // pseudo slots for Format menu
173 rSet
.DisableItem( SID_ALIGN_ANY_LEFT
);
174 rSet
.DisableItem( SID_ALIGN_ANY_HCENTER
);
175 rSet
.DisableItem( SID_ALIGN_ANY_RIGHT
);
176 rSet
.DisableItem( SID_ALIGN_ANY_TOP
);
177 rSet
.DisableItem( SID_ALIGN_ANY_VCENTER
);
178 rSet
.DisableItem( SID_ALIGN_ANY_BOTTOM
);
181 // do not change layer of form controls
182 // #i83729# do not change layer of cell notes (on internal layer)
183 if ( !nMarkCount
|| pView
->HasMarkedControl() || pView
->HasMarkedInternal() )
185 rSet
.DisableItem( SID_OBJECT_HEAVEN
);
186 rSet
.DisableItem( SID_OBJECT_HELL
);
190 if(AreAllObjectsOnLayer(SC_LAYER_FRONT
,rMarkList
))
192 rSet
.DisableItem( SID_OBJECT_HEAVEN
);
194 else if(AreAllObjectsOnLayer(SC_LAYER_BACK
,rMarkList
))
196 rSet
.DisableItem( SID_OBJECT_HELL
);
200 bool bCanRename
= false;
201 if ( nMarkCount
> 1 )
203 // no hypelink options for a selected group
204 rSet
.DisableItem( SID_DRAW_HLINK_EDIT
);
205 rSet
.DisableItem( SID_DRAW_HLINK_DELETE
);
206 rSet
.DisableItem( SID_OPEN_HYPERLINK
);
208 else if ( nMarkCount
== 1 )
210 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
211 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
);
212 if ( !pInfo
|| pInfo
->GetHlink().isEmpty() )
214 rSet
.DisableItem( SID_DRAW_HLINK_DELETE
);
215 rSet
.DisableItem( SID_OPEN_HYPERLINK
);
217 SdrLayerID nLayerID
= pObj
->GetLayer();
218 if ( nLayerID
!= SC_LAYER_INTERN
)
219 bCanRename
= true; // #i51351# anything except internal objects can be renamed
221 // #91929#; don't show original size entry if not possible
222 sal_uInt16 nObjType
= pObj
->GetObjIdentifier();
223 if ( nObjType
== OBJ_OLE2
)
225 SdrOle2Obj
* pOleObj
= static_cast<SdrOle2Obj
*>(rMarkList
.GetMark( 0 )->GetMarkedSdrObj());
226 if (pOleObj
->GetObjRef().is() &&
227 ((pOleObj
->GetObjRef()->getStatus( pOleObj
->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE
) ) )
228 //TODO/LATER: why different slots in Draw and Calc?
229 rSet
.DisableItem(SID_ORIGINALSIZE
);
231 else if ( nObjType
== OBJ_CAPTION
)
233 if ( nLayerID
== SC_LAYER_INTERN
)
235 // SdrCaptionObj() Notes cannot be cut/copy in isolation from
237 rSet
.DisableItem( SID_CUT
);
238 rSet
.DisableItem( SID_COPY
);
239 // Notes always default to Page anchor.
240 rSet
.DisableItem( SID_ANCHOR_TOGGLE
);
247 rSet
.DisableItem( SID_RENAME_OBJECT
);
248 rSet
.DisableItem( SID_TITLE_DESCRIPTION_OBJECT
);
251 if ( !nMarkCount
) // nichts selektiert
254 rSet
.DisableItem( SID_FRAME_UP
);
255 rSet
.DisableItem( SID_FRAME_DOWN
);
256 rSet
.DisableItem( SID_FRAME_TO_TOP
);
257 rSet
.DisableItem( SID_FRAME_TO_BOTTOM
);
258 // Clipboard / loeschen
259 rSet
.DisableItem( SID_DELETE
);
260 rSet
.DisableItem( SID_DELETE_CONTENTS
);
261 rSet
.DisableItem( SID_CUT
);
262 rSet
.DisableItem( SID_COPY
);
264 rSet
.DisableItem( SID_ANCHOR_TOGGLE
);
265 rSet
.DisableItem( SID_ORIGINALSIZE
);
266 rSet
.DisableItem( SID_ATTR_TRANSFORM
);
269 if ( rSet
.GetItemState( SID_ENABLE_HYPHENATION
) != SFX_ITEM_UNKNOWN
)
271 SfxItemSet
aAttrs( pView
->GetModel()->GetItemPool() );
272 pView
->GetAttributes( aAttrs
);
273 if( aAttrs
.GetItemState( EE_PARA_HYPHENATE
) >= SFX_ITEM_AVAILABLE
)
275 bool bValue
= ( (const SfxBoolItem
&) aAttrs
.Get( EE_PARA_HYPHENATE
) ).GetValue();
276 rSet
.Put( SfxBoolItem( SID_ENABLE_HYPHENATION
, bValue
) );
280 svx::ExtrusionBar::getState( pView
, rSet
);
281 svx::FontworkBar::getState( pView
, rSet
);
285 // Attribute fuer Drawing-Objekte
288 void ScDrawShell::GetDrawAttrState( SfxItemSet
& rSet
)
290 Point aMousePos
= pViewData
->GetMousePosPixel();
291 Window
* pWindow
= pViewData
->GetActiveWin();
292 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
293 Point aPos
= pWindow
->PixelToLogic(aMousePos
);
294 bool bHasMarked
= pDrView
->AreObjectsMarked();
298 rSet
.Put( pDrView
->GetAttrFromMarked(false), false );
302 rSet
.Put( pDrView
->GetDefaultAttr() );
305 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
308 // #i52073# when a sheet with an active OLE object is deleted,
309 // the slot state is queried without an active page view
311 // Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
313 // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
314 // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
316 bool bActionItem
= false;
317 if ( pDrView
->IsAction() ) // action rectangle
320 pDrView
->TakeActionRect( aRect
);
321 if ( !aRect
.IsEmpty() )
323 pPV
->LogicToPagePos(aRect
);
324 rSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
325 Size
aSize( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() );
326 rSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, aSize
) );
332 if ( pDrView
->AreObjectsMarked() ) // selected objects
334 Rectangle aRect
= pDrView
->GetAllMarkedRect();
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
) );
340 else // mouse position
342 // aPos is initialized above
343 pPV
->LogicToPagePos(aPos
);
344 rSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aPos
) );
345 rSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, Size( 0, 0 ) ) );
351 void ScDrawShell::GetAttrFuncState(SfxItemSet
&rSet
)
353 // Dialoge fuer Draw-Attribute disablen, wenn noetig
355 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
356 SfxItemSet aViewSet
= pDrView
->GetAttrFromMarked(false);
358 if ( aViewSet
.GetItemState( XATTR_LINESTYLE
) == SFX_ITEM_DEFAULT
)
360 rSet
.DisableItem( SID_ATTRIBUTES_LINE
);
361 rSet
.DisableItem( SID_ATTR_LINEEND_STYLE
); // Tbx-Controller
364 if ( aViewSet
.GetItemState( XATTR_FILLSTYLE
) == SFX_ITEM_DEFAULT
)
365 rSet
.DisableItem( SID_ATTRIBUTES_AREA
);
368 bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo
,const SdrMarkList
& rMark
)
371 sal_uLong nCount
= rMark
.GetMarkCount();
372 for (sal_uLong i
=0; i
<nCount
; i
++)
374 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
375 if ( !pObj
->ISA(SdrUnoObj
) )
377 if(nLayerNo
!=pObj
->GetLayer())
387 void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet
& rSet
)
389 ScDrawView
* pView
= pViewData
->GetScDrawView();
390 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
392 if( rMarkList
.GetMark(0) != 0 )
394 SfxItemSet
aNewAttr(pView
->GetGeoAttrFromMarked());
395 rSet
.Put(aNewAttr
, false);
400 void ScDrawShell::Activate (const bool bMDI
)
404 ContextChangeEventMultiplexer::NotifyContextChange(
405 GetFrame()->GetFrame().GetController(),
406 ::sfx2::sidebar::EnumContext::GetContextEnum(
407 GetSidebarContextName()));
411 ::rtl::OUString
ScDrawShell::GetSidebarContextName (void)
413 return sfx2::sidebar::EnumContext::GetContextName(
414 ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
415 GetDrawView()->GetMarkedObjectList()));
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */