LibreOffice Module sc (master) 1
graphsh.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 <sfx2/objface.hxx>
21#include <vcl/EnumContext.hxx>
22#include <sfx2/opengrf.hxx>
23#include <svx/svdograf.hxx>
24#include <svx/grfflt.hxx>
25#include <svx/grafctrl.hxx>
27#include <svx/graphichelper.hxx>
28#include <svx/svxids.hrc>
29
30#include <graphsh.hxx>
31#include <strings.hrc>
32#include <viewdata.hxx>
33#include <drawview.hxx>
34#include <gridwin.hxx>
35#include <scresid.hxx>
36#include <svx/extedit.hxx>
37
38#define ShellClass_ScGraphicShell
39#include <scslots.hxx>
40
42
43void ScGraphicShell::InitInterface_Impl()
44{
45 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT,
46 SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server,
47 ToolbarId::Graphic_Objectbar);
48
49 GetStaticInterface()->RegisterPopupMenu("graphic");
50}
51
52
54 ScDrawShell(rData)
55{
56 SetName("GraphicObject");
58}
59
61{
62}
63
65{
67
68 if( pView )
70}
71
73{
75
76 if( pView )
77 {
79 Invalidate();
80 }
81}
82
84{
86 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
87 bool bEnable = false;
88
89 if( rMarkList.GetMarkCount() == 1 )
90 {
91 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
92
93 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
94 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
95 bEnable = true;
96 }
97
98 if( !bEnable )
100}
101
103{
105 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
106
107 if( rMarkList.GetMarkCount() == 1 )
108 {
109 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
110
111 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
112 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
113 {
114 GraphicObject aFilterObj( pGraphicObj->GetGraphicObject() );
115
116 if( SvxGraphicFilterResult::NONE ==
117 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
118 {
119 SdrPageView* pPageView = pView->GetSdrPageView();
120
121 if( pPageView )
122 {
123 rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(*pGraphicObj, pGraphicObj->getSdrModelFromSdrObject());
124 OUString aStr = pView->GetDescriptionOfMarkedObjects() + " " + ScResId(SCSTR_UNDO_GRAFFILTER);
125 pView->BegUndo( aStr );
126 pFilteredObj->SetGraphicObject( aFilterObj );
127 pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() );
128 pView->EndUndo();
129 }
130 }
131 }
132 }
133
134 Invalidate();
135}
136
138{
140 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
141 bool bEnable = false;
142 if( rMarkList.GetMarkCount() == 1 )
143 {
144 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
145
146 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
147 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
148 bEnable = true;
149 }
150
151 if (GetObjectShell()->isExportLocked())
152 bEnable = false;
153
154 if( !bEnable )
155 rSet.DisableItem( SID_EXTERNAL_EDIT );
156}
157
159{
161 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
162
163 if( rMarkList.GetMarkCount() == 1 )
164 {
165 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
166
167 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
168 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
169 {
170 GraphicObject aGraphicObject( pGraphicObj->GetGraphicObject() );
171 m_ExternalEdits.push_back( std::make_unique<SdrExternalToolEdit>(
172 pView, pGraphicObj));
173 m_ExternalEdits.back()->Edit( &aGraphicObject );
174 }
175 }
176
177 Invalidate();
178}
179
181{
183 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
184 bool bEnable = false;
185 if( rMarkList.GetMarkCount() == 1 )
186 {
187 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
188
189 if( auto pGraphicObj = dynamic_cast<const SdrGrafObj*>( pObj) )
190 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
191 bEnable = true;
192 }
193
194 if( !bEnable )
195 rSet.DisableItem( SID_COMPRESS_GRAPHIC );
196}
197
199{
201 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
202
203 if( rMarkList.GetMarkCount() == 1 )
204 {
205 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
206
207 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
208 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
209 {
210 CompressGraphicsDialog dialog(GetViewData().GetDialogParent(), pGraphicObj, GetViewData().GetBindings());
211 if (dialog.run() == RET_OK)
212 {
214 SdrPageView* pPageView = pView->GetSdrPageView();
215 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Compress";
216 pView->BegUndo( aUndoString );
217 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject.get() );
218 pView->EndUndo();
219 }
220 }
221 }
222
223 Invalidate();
224}
225
227{
229 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
230 bool bEnable = false;
231 if( rMarkList.GetMarkCount() == 1 )
232 {
233 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
234
235 if( auto pGraphicObj = dynamic_cast<const SdrGrafObj*>( pObj) )
236 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
237 bEnable = true;
238 }
239
240 if( !bEnable )
241 rSet.DisableItem( SID_OBJECT_CROP );
242}
243
245{
247 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
248
249 if( rMarkList.GetMarkCount() == 1 )
250 {
251 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
252
253 if( auto pGraphicObj = dynamic_cast<const SdrGrafObj*>( pObj) )
254 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
255 {
256 pView->SetEditMode(SdrViewEditMode::Edit);
257 pView->SetDragMode(SdrDragMode::Crop);
258 }
259 }
260
261 Invalidate();
262}
263
264void ScGraphicShell::ExecuteSaveGraphic( SAL_UNUSED_PARAMETER SfxRequest& /*rReq*/)
265{
267 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
268 if( rMarkList.GetMarkCount() == 1 )
269 {
270 const SdrGrafObj* pObj = dynamic_cast<const SdrGrafObj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
271 if( pObj && pObj->GetGraphicType() == GraphicType::Bitmap )
272 {
273 GraphicAttr aGraphicAttr = pObj->GetGraphicAttr();
274 short nState = RET_CANCEL;
276 weld::Window* pWinFrame = pWin ? pWin->GetFrameWeld() : nullptr;
277 if (aGraphicAttr != GraphicAttr()) // the image has been modified
278 {
279 if (pWin)
280 {
282 }
283 }
284 else
285 {
286 nState = RET_NO;
287 }
288
289 if (nState == RET_YES)
290 {
292 }
293 else if (nState == RET_NO)
294 {
295 const GraphicObject& aGraphicObject(pObj->GetGraphicObject());
296 GraphicHelper::ExportGraphic(pWinFrame, aGraphicObject.GetGraphic(), "");
297 }
298 }
299 }
300
301 Invalidate();
302}
303
305{
307 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
308 bool bEnable = false;
309 if( rMarkList.GetMarkCount() == 1 )
310 {
311 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
312
313 if( auto pGraphicObj = dynamic_cast<const SdrGrafObj*>( pObj) )
314 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
315 bEnable = true;
316 }
317
318 if (GetObjectShell()->isExportLocked())
319 bEnable = false;
320
321 if( !bEnable )
322 rSet.DisableItem( SID_SAVE_GRAPHIC );
323}
324
325void ScGraphicShell::ExecuteChangePicture( SAL_UNUSED_PARAMETER SfxRequest& /*rReq*/)
326{
328 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
329
330 if( rMarkList.GetMarkCount() == 1 )
331 {
332 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
333
334 if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) )
335 if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap )
336 {
338 SvxOpenGraphicDialog aDlg(ScResId(STR_INSERTGRAPHIC), pWin ? pWin->GetFrameWeld() : nullptr);
339
340 if( aDlg.Execute() == ERRCODE_NONE )
341 {
342 Graphic aGraphic;
343 ErrCode nError = aDlg.GetGraphic(aGraphic);
344 if( nError == ERRCODE_NONE )
345 {
346 rtl::Reference<SdrGrafObj> pNewObject(SdrObject::Clone(*pGraphicObj, pGraphicObj->getSdrModelFromSdrObject()));
347 pNewObject->SetGraphic( aGraphic );
348 SdrPageView* pPageView = pView->GetSdrPageView();
349 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Change";
350 pView->BegUndo( aUndoString );
351 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject.get() );
352 pView->EndUndo();
353 }
354 }
355 }
356 }
357
358 Invalidate();
359}
360
362{
364 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
365 bool bEnable = false;
366 if( rMarkList.GetMarkCount() == 1 )
367 {
368 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
369
370 if( auto pGrafObj = dynamic_cast<const SdrGrafObj*>( pObj) )
371 if( pGrafObj->GetGraphicType() == GraphicType::Bitmap )
372 bEnable = true;
373 }
374
375 if( !bEnable )
376 rSet.DisableItem( SID_CHANGE_PICTURE );
377}
378
379
380/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< SdrGrafObj > GetCompressedSdrGrafObj()
static OUString ExportGraphic(weld::Window *pWin, const Graphic &rGraphic, const OUString &rGraphicName)
static short HasToSaveTransformedImage(weld::Widget *pWin)
const Graphic & GetGraphic() const
ScViewData & GetViewData()
Definition: drawsh.hxx:48
void GetExternalEditState(SfxItemSet &rSet)
Definition: graphsh.cxx:137
void Execute(SfxRequest &rReq)
Definition: graphsh.cxx:72
void GetCompressGraphicState(SfxItemSet &rSet)
Definition: graphsh.cxx:180
void ExecuteCropGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:244
void ExecuteFilter(const SfxRequest &rReq)
Definition: graphsh.cxx:102
void ExecuteCompressGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:198
void GetChangePictureState(SfxItemSet &rSet)
Definition: graphsh.cxx:361
void GetSaveGraphicState(SfxItemSet &rSet)
Definition: graphsh.cxx:304
void GetCropGraphicState(SfxItemSet &rSet)
Definition: graphsh.cxx:226
void ExecuteSaveGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:264
std::vector< std::unique_ptr< SdrExternalToolEdit > > m_ExternalEdits
Definition: graphsh.hxx:39
void ExecuteChangePicture(SfxRequest &rReq)
Definition: graphsh.cxx:325
void GetFilterState(SfxItemSet &rSet)
Definition: graphsh.cxx:83
void ExecuteExternalEdit(SfxRequest &rReq)
Definition: graphsh.cxx:158
void GetAttrState(SfxItemSet &rSet)
Definition: graphsh.cxx:64
ScGraphicShell(ScViewData &rData)
Definition: graphsh.cxx:53
virtual ~ScGraphicShell() override
Definition: graphsh.cxx:60
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3162
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3174
void SetEditMode(SdrViewEditMode eMode)
void ReplaceObjectAtView(SdrObject *pOldObj, SdrPageView &rPV, SdrObject *pNewObj, bool bMark=true)
void BegUndo()
void EndUndo()
GraphicAttr GetGraphicAttr(SdrGrafObjTransformsAttrs nTransformFlags=SdrGrafObjTransformsAttrs::ALL) const
Graphic GetTransformedGraphic(SdrGrafObjTransformsAttrs nTransformFlags=SdrGrafObjTransformsAttrs::ALL) const
GraphicType GetGraphicType() const
const GraphicObject & GetGraphicObject(bool bForceSwapIn=false) const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
void SetDragMode(SdrDragMode eMode)
const SdrMarkList & GetMarkedObjectList() const
OUString const & GetDescriptionOfMarkedObjects() const
SdrObject * GetMarkedSdrObj() const
static rtl::Reference< T > Clone(T const &rObj, SdrModel &rTargetModel)
SdrPageView * GetSdrPageView() const
void DisableItem(sal_uInt16 nWhich)
void SetContextName(const OUString &rsContextName)
virtual void Invalidate(sal_uInt16 nId=0)
virtual SfxObjectShell * GetObjectShell()
void SetName(const OUString &rName)
static void ExecuteGrafAttr(SfxRequest &rReq, SdrView &rView)
static void GetGrafAttrState(SfxItemSet &rSet, SdrView const &rView)
static SvxGraphicFilterResult ExecuteGrfFilterSlot(SfxRequest const &rReq, GraphicObject &rFilterObject)
static void DisableGraphicFilterSlots(SfxItemSet &rSet)
ErrCode GetGraphic(Graphic &) const
static const OUString & GetContextName(const Context eContext)
weld::Window * GetFrameWeld() const
virtual SfxBindings & GetBindings() override
sal_Int32 nState
#define ERRCODE_NONE
aStr
#define SFX_OBJECTBAR_OBJECT
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
static SfxItemSet & rSet
#define SFX_IMPL_INTERFACE(Class, SuperClass)
RET_OK
RET_CANCEL
RET_NO
RET_YES