LibreOffice Module sc (master) 1
tabvwshh.cxx
Go to the documentation of this file.
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 <config_features.h>
21
22#include <basic/sberrors.hxx>
23#include <svx/svdmark.hxx>
24#include <svx/svdoole2.hxx>
25#include <svx/svdview.hxx>
26#include <sfx2/objsh.hxx>
27#include <sfx2/request.hxx>
28#include <basic/sbxcore.hxx>
29#include <svl/stritem.hxx>
30#include <svl/whiter.hxx>
31#include <vcl/svapp.hxx>
32#include <osl/diagnose.h>
33
34#include <tabvwsh.hxx>
35#include <document.hxx>
36#include <sc.hrc>
37#include <drwlayer.hxx>
38#include <retypepassdlg.hxx>
39#include <tabprotection.hxx>
40
41#include <com/sun/star/embed/EmbedVerbs.hpp>
42
43using namespace com::sun::star;
44
46{
47 sal_uInt16 nSlotId = rReq.GetSlot();
48 const SfxItemSet* pReqArgs = rReq.GetArgs();
49
50 // Always activate/deactivate object in the visible View
51
52 ScTabViewShell* pVisibleSh = this;
53 if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
54 {
55 OSL_FAIL("old slot SID_OLE...");
56 }
57
58 switch (nSlotId)
59 {
60 case SID_OLE_SELECT:
61 case SID_OLE_ACTIVATE:
62 {
63 // In both cases, first select in the visible View
64
65 OUString aName;
66 SdrView* pDrView = GetScDrawView();
67 if (pDrView)
68 {
69 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
70 if (rMarkList.GetMarkCount() == 1)
72 }
73 pVisibleSh->SelectObject( aName );
74
75 // activate
76
77 if ( nSlotId == SID_OLE_ACTIVATE )
78 pVisibleSh->DoVerb(css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
79 }
80 break;
81 case SID_OLE_DEACTIVATE:
82 pVisibleSh->DeactivateOle();
83 break;
84
85 case SID_OBJECT_LEFT:
86 case SID_OBJECT_TOP:
87 case SID_OBJECT_WIDTH:
88 case SID_OBJECT_HEIGHT:
89 {
90 bool bDone = false;
91 const SfxPoolItem* pItem;
92 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
93 {
94 tools::Long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
95 if ( nNewVal < 0 )
96 nNewVal = 0;
97
99
100 SdrView* pDrView = GetScDrawView();
101 if ( pDrView )
102 {
103 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
104 if (rMarkList.GetMarkCount() == 1)
105 {
106 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
107 tools::Rectangle aRect = pObj->GetLogicRect();
108
109 if ( nSlotId == SID_OBJECT_LEFT )
110 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
111 else if ( nSlotId == SID_OBJECT_TOP )
112 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
113 else if ( nSlotId == SID_OBJECT_WIDTH )
114 pDrView->ResizeMarkedObj( aRect.TopLeft(),
115 Fraction( nNewVal, aRect.GetWidth() ),
116 Fraction( 1, 1 ) );
117 else // if ( nSlotId == SID_OBJECT_HEIGHT )
118 pDrView->ResizeMarkedObj( aRect.TopLeft(),
119 Fraction( 1, 1 ),
120 Fraction( nNewVal, aRect.GetHeight() ) );
121 bDone = true;
122 }
123 }
124 }
125#if HAVE_FEATURE_SCRIPTING
126 if (!bDone)
128#endif
129 }
130 break;
131
132 }
133}
134
135static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( const SdrView* pDrView )
136{
137 uno::Reference < embed::XEmbeddedObject > xRet;
138 if (pDrView)
139 {
140 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
141 if (rMarkList.GetMarkCount() == 1)
142 {
143 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
144 if (pObj->GetObjIdentifier() == SdrObjKind::OLE2)
145 {
146 SdrOle2Obj* pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
147 xRet = pOle2Obj->GetObjRef();
148 }
149 }
150 }
151
152 return xRet;
153}
154
156{
157 SfxWhichIter aIter(rSet);
158 sal_uInt16 nWhich = aIter.FirstWhich();
159 while ( nWhich )
160 {
161 switch (nWhich)
162 {
163 case SID_ACTIVE_OBJ_NAME:
164 {
165 OUString aName;
166 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetScDrawView() );
167 if (xOLE.is())
168 {
170 }
171 rSet.Put( SfxStringItem( nWhich, aName ) );
172 }
173 break;
174 case SID_OBJECT_LEFT:
175 case SID_OBJECT_TOP:
176 case SID_OBJECT_WIDTH:
177 case SID_OBJECT_HEIGHT:
178 {
179 SdrView* pDrView = GetScDrawView();
180 if ( pDrView )
181 {
182 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
183 if (rMarkList.GetMarkCount() == 1)
184 {
185 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
186 tools::Rectangle aRect = pObj->GetLogicRect();
187
188 tools::Long nVal;
189 if ( nWhich == SID_OBJECT_LEFT )
190 nVal = aRect.Left();
191 else if ( nWhich == SID_OBJECT_TOP )
192 nVal = aRect.Top();
193 else if ( nWhich == SID_OBJECT_WIDTH )
194 nVal = aRect.GetWidth();
195 else // if ( nWhich == SID_OBJECT_HEIGHT )
196 nVal = aRect.GetHeight();
197
199
201 }
202 }
203 }
204 break;
205 }
206 nWhich = aIter.NextWhich();
207 }
208}
209
211{
214
217 rDoc.AddUnoObject(rObject);
218}
219
221{
223
225 {
228 rDoc.RemoveUnoObject(rObject);
229 }
230 else
231 {
232 OSL_FAIL("no accessibility broadcaster?");
233 }
234}
235
237{
239 pAccessibilityBroadcaster->Broadcast( rHint );
240}
241
243{
244 return pAccessibilityBroadcaster != nullptr;
245}
246
248{
250
252 aDlg.SetDataFromDocument(rDoc);
253 aDlg.SetDesiredHash(eDesiredHash);
254 if (aDlg.run() != RET_OK)
255 return false;
256
257 aDlg.WriteNewDataToDocument(rDoc);
258 return true;
259}
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void SetError(ErrCode)
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
static OUString GetVisibleName(const SdrObject *pObj)
Definition: drwlayer.cxx:2424
void WriteNewDataToDocument(ScDocument &rDoc) const
Write the new set of password data to the document instance to overwrite the current ones.
void SetDataFromDocument(const ScDocument &rDoc)
void SetDesiredHash(ScPasswordHash eHash)
virtual short run() override
void AddAccessibilityObject(SfxListener &rObject)
Definition: tabvwshh.cxx:210
bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
Definition: tabvwshh.cxx:247
void GetObjectState(SfxItemSet &rSet)
Definition: tabvwshh.cxx:155
void BroadcastAccessibility(const SfxHint &rHint)
Definition: tabvwshh.cxx:236
void ExecuteObject(const SfxRequest &rReq)
Definition: tabvwshh.cxx:45
bool SelectObject(std::u16string_view rName)
Definition: tabvwsh2.cxx:460
bool HasAccessibilityObjects() const
Definition: tabvwshh.cxx:242
void DeactivateOle()
Definition: tabvwshb.cxx:308
std::unique_ptr< SfxBroadcaster > pAccessibilityBroadcaster
Definition: tabvwsh.hxx:162
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: tabvwshh.cxx:220
virtual ErrCode DoVerb(sal_Int32 nVerb) override
Definition: tabvwshb.cxx:280
ScViewData & GetViewData()
Definition: tabview.hxx:344
ScDrawView * GetScDrawView()
Definition: tabview.hxx:352
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
SfxObjectShell * GetSfxDocShell() const
Definition: viewdata.hxx:358
void ResizeMarkedObj(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bCopy=false)
void MoveMarkedObj(const Size &rSiz, bool bCopy=false)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
virtual SdrObjKind GetObjIdentifier() const
virtual const tools::Rectangle & GetLogicRect() const
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
weld::Window * GetFrameWeld() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
OUString GetEmbeddedObjectName(const css::uno::Reference< css::embed::XEmbeddedObject > &) const
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
OUString aName
long Long
const char GetValue[]
#define ERRCODE_BASIC_BAD_PARAMETER
static SfxItemSet & rSet
ScPasswordHash
static uno::Reference< embed::XEmbeddedObject > lcl_GetSelectedObj(const SdrView *pDrView)
member of ScDrawView?
Definition: tabvwshh.cxx:135
RET_OK