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