Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/embed/EmbedMisc.hpp>
30 : :
31 : : #include "scitems.hxx"
32 : : #include <editeng/eeitem.hxx>
33 : : #include <editeng/sizeitem.hxx>
34 : : #include <svx/svdpagv.hxx>
35 : : #include <svx/xdef.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <sfx2/objsh.hxx>
38 : : #include <sfx2/viewfrm.hxx>
39 : : #include <svl/ptitem.hxx>
40 : : #include <svl/whiter.hxx>
41 : : #include <svx/svdobj.hxx>
42 : : #include <svx/svdouno.hxx>
43 : : #include <svx/extrusionbar.hxx>
44 : : #include <svx/fontworkbar.hxx>
45 : :
46 : : #include "drawsh.hxx"
47 : : #include "drawview.hxx"
48 : : #include "viewdata.hxx"
49 : : #include "sc.hrc"
50 : : #include "tabvwsh.hxx"
51 : : #include "document.hxx"
52 : : #include "drwlayer.hxx"
53 : : #include "userdat.hxx"
54 : : #include <svx/svdoole2.hxx>
55 : : #include <svx/svdocapt.hxx>
56 : :
57 : : sal_uInt16 ScGetFontWorkId(); // in drtxtob
58 : :
59 : : using namespace com::sun::star;
60 : :
61 : : //------------------------------------------------------------------
62 : :
63 : 0 : ScDrawShell::ScDrawShell( ScViewData* pData ) :
64 : 0 : SfxShell(pData->GetViewShell()),
65 : 0 : pViewData( pData )
66 : : {
67 [ # # ]: 0 : SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
68 [ # # ][ # # ]: 0 : ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
69 [ # # ]: 0 : SetUndoManager( pMgr );
70 [ # # ][ # # ]: 0 : if ( !pViewData->GetDocument()->IsUndoEnabled() )
71 : : {
72 [ # # ]: 0 : pMgr->SetMaxUndoActionCount( 0 );
73 : : }
74 [ # # ]: 0 : SetHelpId( HID_SCSHELL_DRAWSH );
75 [ # # ][ # # ]: 0 : SetName(rtl::OUString("Drawing"));
[ # # ]
76 : 0 : }
77 : :
78 : 0 : ScDrawShell::~ScDrawShell()
79 : : {
80 [ # # ]: 0 : }
81 : :
82 : 0 : void ScDrawShell::GetState( SfxItemSet& rSet ) // Zustaende / Toggles
83 : : {
84 : 0 : ScDrawView* pView = pViewData->GetScDrawView();
85 : 0 : SdrDragMode eMode = pView->GetDragMode();
86 : :
87 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
88 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
89 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
90 : :
91 : 0 : sal_uInt16 nFWId = ScGetFontWorkId();
92 : 0 : SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
93 [ # # ]: 0 : rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
94 : :
95 : : // Notes always default to Page anchor.
96 : 0 : bool bDisableAnchor = false;
97 : 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
98 : 0 : sal_uLong nMarkCount = rMarkList.GetMarkCount();
99 [ # # ]: 0 : if ( nMarkCount == 1 )
100 : : {
101 : 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
102 [ # # ]: 0 : if( ScDrawLayer::IsNoteCaption( pObj ) )
103 : : {
104 : 0 : bDisableAnchor = true;
105 : 0 : rSet.DisableItem( SID_ANCHOR_PAGE );
106 : 0 : rSet.DisableItem( SID_ANCHOR_CELL );
107 : : }
108 : : }
109 : :
110 [ # # ]: 0 : if ( !bDisableAnchor )
111 : : {
112 [ # # # ]: 0 : switch( pView->GetAnchorType() )
113 : : {
114 : : case SCA_PAGE:
115 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_True ) );
116 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
117 : 0 : break;
118 : :
119 : : case SCA_CELL:
120 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
121 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_True ) );
122 : 0 : break;
123 : :
124 : : default:
125 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
126 [ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
127 : 0 : break;
128 : : }
129 : : }
130 : 0 : }
131 : :
132 : 0 : void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // Funktionen disablen
133 : : {
134 : 0 : ScDrawView* pView = pViewData->GetScDrawView();
135 : :
136 : : // call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
137 : : // is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
138 [ # # ]: 0 : if (!pView->IsMirrorAllowed(sal_True,sal_True))
139 : : {
140 : 0 : rSet.DisableItem( SID_MIRROR_HORIZONTAL );
141 : 0 : rSet.DisableItem( SID_MIRROR_VERTICAL );
142 : : }
143 : :
144 : 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
145 : 0 : sal_uLong nMarkCount = rMarkList.GetMarkCount();
146 : :
147 [ # # ][ # # ]: 0 : if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
[ # # ]
148 : 0 : rSet.DisableItem( SID_GROUP );
149 [ # # ][ # # ]: 0 : if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
[ # # ]
150 : 0 : rSet.DisableItem( SID_UNGROUP );
151 [ # # ][ # # ]: 0 : if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
[ # # ]
152 : 0 : rSet.DisableItem( SID_ENTER_GROUP );
153 [ # # ]: 0 : if ( !pView->IsGroupEntered() )
154 : 0 : rSet.DisableItem( SID_LEAVE_GROUP );
155 : :
156 [ # # ]: 0 : if ( nMarkCount <= 1 ) // nichts oder nur ein Objekt selektiert
157 : : {
158 : : // Ausrichtung
159 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_LEFT ); // keine Ausrichtung an der Seite
160 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
161 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
162 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_UP );
163 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
164 : 0 : rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
165 : :
166 : : // pseudo slots for Format menu
167 : 0 : rSet.DisableItem( SID_ALIGN_ANY_LEFT );
168 : 0 : rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
169 : 0 : rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
170 : 0 : rSet.DisableItem( SID_ALIGN_ANY_TOP );
171 : 0 : rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
172 : 0 : rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
173 : : }
174 : :
175 : : // do not change layer of form controls
176 : : // #i83729# do not change layer of cell notes (on internal layer)
177 [ # # ][ # # ]: 0 : if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
[ # # ][ # # ]
178 : : {
179 : 0 : rSet.DisableItem( SID_OBJECT_HEAVEN );
180 : 0 : rSet.DisableItem( SID_OBJECT_HELL );
181 : : }
182 : : else
183 : : {
184 [ # # ]: 0 : if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
185 : : {
186 : 0 : rSet.DisableItem( SID_OBJECT_HEAVEN );
187 : : }
188 [ # # ]: 0 : else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
189 : : {
190 : 0 : rSet.DisableItem( SID_OBJECT_HELL );
191 : : }
192 : : }
193 : :
194 : 0 : sal_Bool bCanRename = false;
195 [ # # ]: 0 : if ( nMarkCount > 1 )
196 : : {
197 : : // no hypelink options for a selected group
198 : 0 : rSet.DisableItem( SID_DRAW_HLINK_EDIT );
199 : 0 : rSet.DisableItem( SID_DRAW_HLINK_DELETE );
200 : 0 : rSet.DisableItem( SID_OPEN_HYPERLINK );
201 : : }
202 [ # # ]: 0 : else if ( nMarkCount == 1 )
203 : : {
204 : 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
205 : 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
206 [ # # ][ # # ]: 0 : if ( !pInfo || pInfo->GetHlink().isEmpty() )
[ # # ]
207 : : {
208 : 0 : rSet.DisableItem( SID_DRAW_HLINK_DELETE );
209 : 0 : rSet.DisableItem( SID_OPEN_HYPERLINK );
210 : : }
211 : 0 : SdrLayerID nLayerID = pObj->GetLayer();
212 [ # # ]: 0 : if ( nLayerID != SC_LAYER_INTERN )
213 : 0 : bCanRename = sal_True; // #i51351# anything except internal objects can be renamed
214 : :
215 : : // #91929#; don't show original size entry if not possible
216 : 0 : sal_uInt16 nObjType = pObj->GetObjIdentifier();
217 [ # # ]: 0 : if ( nObjType == OBJ_OLE2 )
218 : : {
219 : 0 : SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
220 [ # # ][ # # ]: 0 : if (pOleObj->GetObjRef().is() &&
[ # # ]
[ # # # # ]
[ # # ]
221 [ # # ][ # # ]: 0 : ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
[ # # ][ # # ]
[ # # ][ # # ]
222 : : //TODO/LATER: why different slots in Draw and Calc?
223 : 0 : rSet.DisableItem(SID_ORIGINALSIZE);
224 : : }
225 [ # # ]: 0 : else if ( nObjType == OBJ_CAPTION )
226 : : {
227 [ # # ]: 0 : if ( nLayerID == SC_LAYER_INTERN )
228 : : {
229 : : // SdrCaptionObj() Notes cannot be cut/copy in isolation from
230 : : // their cells.
231 : 0 : rSet.DisableItem( SID_CUT );
232 : 0 : rSet.DisableItem( SID_COPY );
233 : : // Notes always default to Page anchor.
234 : 0 : rSet.DisableItem( SID_ANCHOR_TOGGLE );
235 : : }
236 : : }
237 : : }
238 [ # # ]: 0 : if ( !bCanRename )
239 : : {
240 : : // #i68101#
241 : 0 : rSet.DisableItem( SID_RENAME_OBJECT );
242 : 0 : rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
243 : : }
244 : :
245 [ # # ]: 0 : if ( !nMarkCount ) // nichts selektiert
246 : : {
247 : : // Anordnung
248 : 0 : rSet.DisableItem( SID_FRAME_UP );
249 : 0 : rSet.DisableItem( SID_FRAME_DOWN );
250 : 0 : rSet.DisableItem( SID_FRAME_TO_TOP );
251 : 0 : rSet.DisableItem( SID_FRAME_TO_BOTTOM );
252 : : // Clipboard / loeschen
253 : 0 : rSet.DisableItem( SID_DELETE );
254 : 0 : rSet.DisableItem( SID_DELETE_CONTENTS );
255 : 0 : rSet.DisableItem( SID_CUT );
256 : 0 : rSet.DisableItem( SID_COPY );
257 : : // sonstiges
258 : 0 : rSet.DisableItem( SID_ANCHOR_TOGGLE );
259 : 0 : rSet.DisableItem( SID_ORIGINALSIZE );
260 : 0 : rSet.DisableItem( SID_ATTR_TRANSFORM );
261 : : }
262 : :
263 [ # # ]: 0 : if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
264 : : {
265 [ # # ]: 0 : SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
266 [ # # ]: 0 : pView->GetAttributes( aAttrs );
267 [ # # ][ # # ]: 0 : if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
268 : : {
269 [ # # ]: 0 : sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
270 [ # # ][ # # ]: 0 : rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
[ # # ]
271 [ # # ]: 0 : }
272 : : }
273 : :
274 : 0 : svx::ExtrusionBar::getState( pView, rSet );
275 : 0 : svx::FontworkBar::getState( pView, rSet );
276 : 0 : }
277 : :
278 : : //
279 : : // Attribute fuer Drawing-Objekte
280 : : //
281 : :
282 : 0 : void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
283 : : {
284 [ # # ]: 0 : Point aMousePos = pViewData->GetMousePosPixel();
285 [ # # ]: 0 : Window* pWindow = pViewData->GetActiveWin();
286 [ # # ]: 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
287 [ # # ]: 0 : Point aPos = pWindow->PixelToLogic(aMousePos);
288 : 0 : sal_Bool bHasMarked = pDrView->AreObjectsMarked();
289 : :
290 [ # # ]: 0 : if( bHasMarked )
291 : : {
292 [ # # ][ # # ]: 0 : rSet.Put( pDrView->GetAttrFromMarked(false) );
[ # # ]
293 : :
294 : : // Wenn die View selektierte Objekte besitzt, muessen entspr. Items
295 : : // von SFX_ITEM_DEFAULT (_ON) auf SFX_ITEM_DISABLED geaendert werden
296 : :
297 [ # # ]: 0 : SfxWhichIter aIter( rSet, XATTR_LINE_FIRST, XATTR_FILL_LAST );
298 [ # # ]: 0 : sal_uInt16 nWhich = aIter.FirstWhich();
299 [ # # ]: 0 : while( nWhich )
300 : : {
301 [ # # ][ # # ]: 0 : if( SFX_ITEM_DEFAULT == rSet.GetItemState( nWhich ) )
302 [ # # ]: 0 : rSet.DisableItem( nWhich );
303 : :
304 [ # # ]: 0 : nWhich = aIter.NextWhich();
305 [ # # ]: 0 : }
306 : : }
307 : : else
308 [ # # ]: 0 : rSet.Put( pDrView->GetDefaultAttr() );
309 : :
310 : 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
311 [ # # ]: 0 : if ( pPV )
312 : : {
313 : : // #i52073# when a sheet with an active OLE object is deleted,
314 : : // the slot state is queried without an active page view
315 : :
316 : : // Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
317 : :
318 : : // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
319 : : // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
320 : :
321 : 0 : sal_Bool bActionItem = false;
322 [ # # ][ # # ]: 0 : if ( pDrView->IsAction() ) // action rectangle
323 : : {
324 [ # # ]: 0 : Rectangle aRect;
325 [ # # ]: 0 : pDrView->TakeActionRect( aRect );
326 [ # # ][ # # ]: 0 : if ( !aRect.IsEmpty() )
327 : : {
328 [ # # ]: 0 : pPV->LogicToPagePos(aRect);
329 [ # # ][ # # ]: 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
[ # # ]
330 : 0 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
331 [ # # ][ # # ]: 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
[ # # ]
332 : 0 : bActionItem = sal_True;
333 : : }
334 : : }
335 [ # # ]: 0 : if ( !bActionItem )
336 : : {
337 [ # # ]: 0 : if ( pDrView->AreObjectsMarked() ) // selected objects
338 : : {
339 [ # # ]: 0 : Rectangle aRect = pDrView->GetAllMarkedRect();
340 [ # # ]: 0 : pPV->LogicToPagePos(aRect);
341 [ # # ][ # # ]: 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
[ # # ]
342 : 0 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
343 [ # # ][ # # ]: 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
[ # # ]
344 : : }
345 : : else // mouse position
346 : : {
347 : : // aPos is initialized above
348 : 0 : pPV->LogicToPagePos(aPos);
349 [ # # ][ # # ]: 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
[ # # ]
350 [ # # ][ # # ]: 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
[ # # ]
351 : : }
352 : : }
353 : : }
354 : 0 : }
355 : :
356 : 0 : void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
357 : : {
358 : : // Dialoge fuer Draw-Attribute disablen, wenn noetig
359 : :
360 [ # # ]: 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
361 [ # # ]: 0 : SfxItemSet aViewSet = pDrView->GetAttrFromMarked(false);
362 : :
363 [ # # ][ # # ]: 0 : if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
364 : : {
365 [ # # ]: 0 : rSet.DisableItem( SID_ATTRIBUTES_LINE );
366 [ # # ]: 0 : rSet.DisableItem( SID_ATTR_LINEEND_STYLE ); // Tbx-Controller
367 : : }
368 : :
369 [ # # ][ # # ]: 0 : if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
370 [ # # ][ # # ]: 0 : rSet.DisableItem( SID_ATTRIBUTES_AREA );
371 : 0 : }
372 : :
373 : 0 : sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
374 : : {
375 : 0 : sal_Bool bResult=sal_True;
376 : 0 : sal_uLong nCount = rMark.GetMarkCount();
377 [ # # ]: 0 : for (sal_uLong i=0; i<nCount; i++)
378 : : {
379 : 0 : SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
380 [ # # ]: 0 : if ( !pObj->ISA(SdrUnoObj) )
381 : : {
382 [ # # ]: 0 : if(nLayerNo!=pObj->GetLayer())
383 : : {
384 : 0 : bResult=false;
385 : 0 : break;
386 : : }
387 : : }
388 : : }
389 : 0 : return bResult;
390 : : }
391 : :
392 : :
393 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|