1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawsh2.cxx,v $
10 * $Revision: 1.26.128.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 //------------------------------------------------------------------
35 #include <com/sun/star/embed/EmbedMisc.hpp>
37 #include "scitems.hxx"
38 #include <svx/eeitem.hxx>
39 #include <svx/sizeitem.hxx>
40 #include <svx/svdpagv.hxx>
41 #include <svx/xdef.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <svtools/ptitem.hxx>
46 #include <svtools/whiter.hxx>
47 #include <svx/svdobj.hxx>
48 #include <svx/svdouno.hxx>
49 #include <svx/extrusionbar.hxx>
50 #include <svx/fontworkbar.hxx>
53 #include "drawview.hxx"
54 #include "viewdata.hxx"
56 #include "tabvwsh.hxx"
57 #include "document.hxx"
58 #include "drwlayer.hxx"
59 #include "userdat.hxx"
60 #include <svx/svdoole2.hxx>
61 #include <svx/svdocapt.hxx>
63 USHORT
ScGetFontWorkId(); // in drtxtob
65 using namespace com::sun::star
;
67 //------------------------------------------------------------------
69 ScDrawShell::ScDrawShell( ScViewData
* pData
) :
70 SfxShell(pData
->GetViewShell()),
73 SetPool( &pViewData
->GetScDrawView()->GetModel()->GetItemPool() );
74 SfxUndoManager
* pMgr
= pViewData
->GetSfxDocShell()->GetUndoManager();
75 SetUndoManager( pMgr
);
76 if ( !pViewData
->GetDocument()->IsUndoEnabled() )
78 pMgr
->SetMaxUndoActionCount( 0 );
80 SetHelpId( HID_SCSHELL_DRAWSH
);
81 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Drawing")));
84 ScDrawShell::~ScDrawShell()
88 void ScDrawShell::GetState( SfxItemSet
& rSet
) // Zustaende / Toggles
90 ScDrawView
* pView
= pViewData
->GetScDrawView();
91 SdrDragMode eMode
= pView
->GetDragMode();
93 rSet
.Put( SfxBoolItem( SID_OBJECT_ROTATE
, eMode
== SDRDRAG_ROTATE
) );
94 rSet
.Put( SfxBoolItem( SID_OBJECT_MIRROR
, eMode
== SDRDRAG_MIRROR
) );
95 rSet
.Put( SfxBoolItem( SID_BEZIER_EDIT
, !pView
->IsFrameDragSingles() ) );
97 USHORT nFWId
= ScGetFontWorkId();
98 SfxViewFrame
* pViewFrm
= pViewData
->GetViewShell()->GetViewFrame();
99 rSet
.Put(SfxBoolItem(SID_FONTWORK
, pViewFrm
->HasChildWindow(nFWId
)));
101 // Notes always default to Page anchor.
102 bool bDisableAnchor
= false;
103 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
104 ULONG nMarkCount
= rMarkList
.GetMarkCount();
105 if ( nMarkCount
== 1 )
107 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
108 if( ScDrawLayer::IsNoteCaption( pObj
) )
110 bDisableAnchor
= true;
111 rSet
.DisableItem( SID_ANCHOR_PAGE
);
112 rSet
.DisableItem( SID_ANCHOR_CELL
);
116 if ( !bDisableAnchor
)
118 switch( pView
->GetAnchor() )
121 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, TRUE
) );
122 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, FALSE
) );
126 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, FALSE
) );
127 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, TRUE
) );
131 rSet
.Put( SfxBoolItem( SID_ANCHOR_PAGE
, FALSE
) );
132 rSet
.Put( SfxBoolItem( SID_ANCHOR_CELL
, FALSE
) );
138 void ScDrawShell::GetDrawFuncState( SfxItemSet
& rSet
) // Funktionen disablen
140 ScDrawView
* pView
= pViewData
->GetScDrawView();
142 // #111711# call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
143 // is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
144 if (!pView
->IsMirrorAllowed(TRUE
,TRUE
))
146 rSet
.DisableItem( SID_MIRROR_HORIZONTAL
);
147 rSet
.DisableItem( SID_MIRROR_VERTICAL
);
150 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
151 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 // #158385# #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().getLength() == 0) )
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 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
) );
300 // Wenn die View selektierte Objekte besitzt, muessen entspr. Items
301 // von SFX_ITEM_DEFAULT (_ON) auf SFX_ITEM_DISABLED geaendert werden
303 SfxWhichIter
aIter( rSet
, XATTR_LINE_FIRST
, XATTR_FILL_LAST
);
304 USHORT nWhich
= aIter
.FirstWhich();
307 if( SFX_ITEM_DEFAULT
== rSet
.GetItemState( nWhich
) )
308 rSet
.DisableItem( nWhich
);
310 nWhich
= aIter
.NextWhich();
314 rSet
.Put( pDrView
->GetDefaultAttr() );
316 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
319 // #i52073# when a sheet with an active OLE object is deleted,
320 // the slot state is queried without an active page view
322 // Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
324 // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
325 // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
327 BOOL bActionItem
= FALSE
;
328 if ( pDrView
->IsAction() ) // action rectangle
331 pDrView
->TakeActionRect( aRect
);
332 if ( !aRect
.IsEmpty() )
334 pPV
->LogicToPagePos(aRect
);
335 rSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aRect
.TopLeft() ) );
336 Size
aSize( aRect
.Right() - aRect
.Left(), aRect
.Bottom() - aRect
.Top() );
337 rSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, aSize
) );
343 if ( pDrView
->AreObjectsMarked() ) // selected objects
345 Rectangle aRect
= pDrView
->GetAllMarkedRect();
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
) );
351 else // mouse position
353 // aPos is initialized above
354 pPV
->LogicToPagePos(aPos
);
355 rSet
.Put( SfxPointItem( SID_ATTR_POSITION
, aPos
) );
356 rSet
.Put( SvxSizeItem( SID_ATTR_SIZE
, Size( 0, 0 ) ) );
362 void ScDrawShell::GetAttrFuncState(SfxItemSet
&rSet
)
364 // Dialoge fuer Draw-Attribute disablen, wenn noetig
366 ScDrawView
* pDrView
= pViewData
->GetScDrawView();
367 SfxItemSet aViewSet
= pDrView
->GetAttrFromMarked(FALSE
);
369 if ( aViewSet
.GetItemState( XATTR_LINESTYLE
) == SFX_ITEM_DEFAULT
)
371 rSet
.DisableItem( SID_ATTRIBUTES_LINE
);
372 rSet
.DisableItem( SID_ATTR_LINEEND_STYLE
); // Tbx-Controller
375 if ( aViewSet
.GetItemState( XATTR_FILLSTYLE
) == SFX_ITEM_DEFAULT
)
376 rSet
.DisableItem( SID_ATTRIBUTES_AREA
);
379 BOOL
ScDrawShell::AreAllObjectsOnLayer(USHORT nLayerNo
,const SdrMarkList
& rMark
)
382 ULONG nCount
= rMark
.GetMarkCount();
383 for (ULONG i
=0; i
<nCount
; i
++)
385 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
386 if ( !pObj
->ISA(SdrUnoObj
) )
388 if(nLayerNo
!=pObj
->GetLayer())