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 : #include <svx/sidebar/SelectionChangeHandler.hxx>
37 : #include <svx/sidebar/SelectionAnalyzer.hxx>
38 : #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
39 :
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 "drtxtob.hxx"
49 : #include <gridwin.hxx>
50 : #include <svx/svdoole2.hxx>
51 : #include <svx/svdocapt.hxx>
52 :
53 : #include <boost/bind.hpp>
54 :
55 : using namespace com::sun::star;
56 :
57 2 : ScDrawShell::ScDrawShell( ScViewData* pData ) :
58 2 : SfxShell(pData->GetViewShell()),
59 : pViewData( pData ),
60 : mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
61 : ::boost::bind(&ScDrawShell::GetSidebarContextName, this),
62 2 : GetFrame()->GetFrame().GetController(),
63 4 : sfx2::sidebar::EnumContext::Context_Cell))
64 : {
65 2 : SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
66 2 : ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
67 2 : SetUndoManager( pMgr );
68 2 : if ( !pViewData->GetDocument()->IsUndoEnabled() )
69 : {
70 0 : pMgr->SetMaxUndoActionCount( 0 );
71 : }
72 2 : SetHelpId( HID_SCSHELL_DRAWSH );
73 2 : SetName(OUString("Drawing"));
74 :
75 2 : mpSelectionChangeHandler->Connect();
76 2 : }
77 :
78 6 : ScDrawShell::~ScDrawShell()
79 : {
80 2 : mpSelectionChangeHandler->Disconnect();
81 4 : }
82 :
83 0 : void ScDrawShell::GetState( SfxItemSet& rSet ) // Zustaende / Toggles
84 : {
85 0 : ScDrawView* pView = pViewData->GetScDrawView();
86 0 : SdrDragMode eMode = pView->GetDragMode();
87 :
88 0 : rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
89 0 : rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
90 0 : rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
91 :
92 0 : sal_uInt16 nFWId = ScGetFontWorkId();
93 0 : SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
94 0 : rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
95 :
96 : // Notes always default to Page anchor.
97 0 : bool bDisableAnchor = false;
98 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
99 0 : if ( rMarkList.GetMarkCount() == 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, 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, 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(true,true))
139 : {
140 0 : rSet.DisableItem( SID_MIRROR_HORIZONTAL );
141 0 : rSet.DisableItem( SID_MIRROR_VERTICAL );
142 0 : rSet.DisableItem( SID_FLIP_HORIZONTAL );
143 0 : rSet.DisableItem( SID_FLIP_VERTICAL );
144 : }
145 :
146 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
147 0 : const size_t nMarkCount = rMarkList.GetMarkCount();
148 :
149 0 : if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
150 0 : rSet.DisableItem( SID_GROUP );
151 0 : if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
152 0 : rSet.DisableItem( SID_UNGROUP );
153 0 : if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
154 0 : rSet.DisableItem( SID_ENTER_GROUP );
155 0 : if ( !pView->IsGroupEntered() )
156 0 : rSet.DisableItem( SID_LEAVE_GROUP );
157 :
158 0 : if ( nMarkCount <= 1 ) // nichts oder nur ein Objekt selektiert
159 : {
160 : // Ausrichtung
161 0 : rSet.DisableItem( SID_OBJECT_ALIGN_LEFT ); // keine Ausrichtung an der Seite
162 0 : rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
163 0 : rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
164 0 : rSet.DisableItem( SID_OBJECT_ALIGN_UP );
165 0 : rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
166 0 : rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
167 :
168 : // pseudo slots for Format menu
169 0 : rSet.DisableItem( SID_ALIGN_ANY_LEFT );
170 0 : rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
171 0 : rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
172 0 : rSet.DisableItem( SID_ALIGN_ANY_TOP );
173 0 : rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
174 0 : rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
175 : }
176 :
177 : // do not change layer of form controls
178 : // #i83729# do not change layer of cell notes (on internal layer)
179 0 : if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
180 : {
181 0 : rSet.DisableItem( SID_OBJECT_HEAVEN );
182 0 : rSet.DisableItem( SID_OBJECT_HELL );
183 : }
184 : else
185 : {
186 0 : if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
187 : {
188 0 : rSet.DisableItem( SID_OBJECT_HEAVEN );
189 : }
190 0 : else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
191 : {
192 0 : rSet.DisableItem( SID_OBJECT_HELL );
193 : }
194 : }
195 :
196 0 : bool bCanRename = false;
197 0 : if ( nMarkCount > 1 )
198 : {
199 : // no hypelink options for a selected group
200 0 : rSet.DisableItem( SID_DRAW_HLINK_EDIT );
201 0 : rSet.DisableItem( SID_DRAW_HLINK_DELETE );
202 0 : rSet.DisableItem( SID_OPEN_HYPERLINK );
203 : }
204 0 : else if ( nMarkCount == 1 )
205 : {
206 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
207 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
208 0 : if ( !pInfo || pInfo->GetHlink().isEmpty() )
209 : {
210 0 : rSet.DisableItem( SID_DRAW_HLINK_DELETE );
211 0 : rSet.DisableItem( SID_OPEN_HYPERLINK );
212 : }
213 0 : SdrLayerID nLayerID = pObj->GetLayer();
214 0 : if ( nLayerID != SC_LAYER_INTERN )
215 0 : bCanRename = true; // #i51351# anything except internal objects can be renamed
216 :
217 : // #91929#; don't show original size entry if not possible
218 0 : sal_uInt16 nObjType = pObj->GetObjIdentifier();
219 0 : if ( nObjType == OBJ_OLE2 )
220 : {
221 0 : SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
222 0 : if (pOleObj->GetObjRef().is() &&
223 0 : ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
224 : //TODO/LATER: why different slots in Draw and Calc?
225 0 : rSet.DisableItem(SID_ORIGINALSIZE);
226 : }
227 0 : else if ( nObjType == OBJ_CAPTION )
228 : {
229 0 : if ( nLayerID == SC_LAYER_INTERN )
230 : {
231 : // SdrCaptionObj() Notes cannot be cut/copy in isolation from
232 : // their cells.
233 0 : rSet.DisableItem( SID_CUT );
234 0 : rSet.DisableItem( SID_COPY );
235 : // Notes always default to Page anchor.
236 0 : rSet.DisableItem( SID_ANCHOR_TOGGLE );
237 : }
238 : }
239 : }
240 0 : if ( !bCanRename )
241 : {
242 : // #i68101#
243 0 : rSet.DisableItem( SID_RENAME_OBJECT );
244 0 : rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
245 : }
246 :
247 0 : if ( !nMarkCount ) // nichts selektiert
248 : {
249 : // Anordnung
250 0 : rSet.DisableItem( SID_FRAME_UP );
251 0 : rSet.DisableItem( SID_FRAME_DOWN );
252 0 : rSet.DisableItem( SID_FRAME_TO_TOP );
253 0 : rSet.DisableItem( SID_FRAME_TO_BOTTOM );
254 : // Clipboard / loeschen
255 0 : rSet.DisableItem( SID_DELETE );
256 0 : rSet.DisableItem( SID_DELETE_CONTENTS );
257 0 : rSet.DisableItem( SID_CUT );
258 0 : rSet.DisableItem( SID_COPY );
259 : // sonstiges
260 0 : rSet.DisableItem( SID_ANCHOR_TOGGLE );
261 0 : rSet.DisableItem( SID_ORIGINALSIZE );
262 0 : rSet.DisableItem( SID_ATTR_TRANSFORM );
263 : }
264 :
265 0 : if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SfxItemState::UNKNOWN )
266 : {
267 0 : SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
268 0 : pView->GetAttributes( aAttrs );
269 0 : if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT )
270 : {
271 0 : bool bValue = static_cast<const SfxBoolItem&>( aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
272 0 : rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
273 0 : }
274 : }
275 :
276 0 : svx::ExtrusionBar::getState( pView, rSet );
277 0 : svx::FontworkBar::getState( pView, rSet );
278 0 : }
279 :
280 : // Attribute fuer Drawing-Objekte
281 :
282 0 : void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
283 : {
284 0 : Point aMousePos = pViewData->GetMousePosPixel();
285 0 : vcl::Window* pWindow = pViewData->GetActiveWin();
286 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
287 0 : Point aPos = pWindow->PixelToLogic(aMousePos);
288 0 : bool bHasMarked = pDrView->AreObjectsMarked();
289 :
290 0 : if( bHasMarked )
291 : {
292 0 : rSet.Put( pDrView->GetAttrFromMarked(false), false );
293 : }
294 : else
295 : {
296 0 : rSet.Put( pDrView->GetDefaultAttr() );
297 : }
298 :
299 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
300 0 : if ( pPV )
301 : {
302 : // #i52073# when a sheet with an active OLE object is deleted,
303 : // the slot state is queried without an active page view
304 :
305 : // Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
306 :
307 : // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
308 : // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
309 :
310 0 : bool bActionItem = false;
311 0 : if ( pDrView->IsAction() ) // action rectangle
312 : {
313 0 : Rectangle aRect;
314 0 : pDrView->TakeActionRect( aRect );
315 0 : if ( !aRect.IsEmpty() )
316 : {
317 0 : pPV->LogicToPagePos(aRect);
318 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
319 0 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
320 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
321 0 : bActionItem = true;
322 : }
323 : }
324 0 : if ( !bActionItem )
325 : {
326 0 : if ( pDrView->AreObjectsMarked() ) // selected objects
327 : {
328 0 : Rectangle aRect = pDrView->GetAllMarkedRect();
329 0 : pPV->LogicToPagePos(aRect);
330 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
331 0 : Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
332 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
333 : }
334 : else // mouse position
335 : {
336 : // aPos is initialized above
337 0 : pPV->LogicToPagePos(aPos);
338 0 : rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
339 0 : rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
340 : }
341 : }
342 : }
343 0 : }
344 :
345 0 : void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
346 : {
347 : // Dialoge fuer Draw-Attribute disablen, wenn noetig
348 :
349 0 : ScDrawView* pDrView = pViewData->GetScDrawView();
350 0 : SfxItemSet aViewSet = pDrView->GetAttrFromMarked(false);
351 :
352 0 : if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SfxItemState::DEFAULT )
353 : {
354 0 : rSet.DisableItem( SID_ATTRIBUTES_LINE );
355 0 : rSet.DisableItem( SID_ATTR_LINEEND_STYLE ); // Tbx-Controller
356 : }
357 :
358 0 : if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SfxItemState::DEFAULT )
359 0 : rSet.DisableItem( SID_ATTRIBUTES_AREA );
360 0 : }
361 :
362 0 : bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
363 : {
364 0 : bool bResult=true;
365 0 : const size_t nCount = rMark.GetMarkCount();
366 0 : for (size_t i=0; i<nCount; ++i)
367 : {
368 0 : SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
369 0 : if ( !pObj->ISA(SdrUnoObj) )
370 : {
371 0 : if(nLayerNo!=pObj->GetLayer())
372 : {
373 0 : bResult=false;
374 0 : break;
375 : }
376 : }
377 : }
378 0 : return bResult;
379 : }
380 :
381 0 : void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
382 : {
383 0 : ScDrawView* pView = pViewData->GetScDrawView();
384 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
385 :
386 0 : if( rMarkList.GetMark(0) != 0 )
387 : {
388 0 : SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
389 0 : rSet.Put(aNewAttr, false);
390 : }
391 0 : }
392 :
393 12 : void ScDrawShell::Activate (const bool bMDI)
394 : {
395 : (void)bMDI;
396 :
397 : ContextChangeEventMultiplexer::NotifyContextChange(
398 12 : GetFrame()->GetFrame().GetController(),
399 : ::sfx2::sidebar::EnumContext::GetContextEnum(
400 24 : GetSidebarContextName()));
401 12 : }
402 :
403 32 : ::rtl::OUString ScDrawShell::GetSidebarContextName (void)
404 : {
405 : return sfx2::sidebar::EnumContext::GetContextName(
406 : ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
407 32 : GetDrawView()->GetMarkedObjectList()));
408 228 : }
409 :
410 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|