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