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(rData)
55 {
56  SetName("GraphicObject");
58 }
59 
61 {
62 }
63 
65 {
67 
68  if( pView )
70 }
71 
73 {
75 
76  if( pView )
77  {
78  SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
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 {
104  ScDrawView* pView = GetViewData().GetScDrawView();
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  SdrGrafObj* pFilteredObj(static_cast<SdrGrafObj*>(pObj->CloneSdrObject(pObj->getSdrModelFromSdrObject())));
124  OUString aStr = pView->GetDescriptionOfMarkedObjects() + " " + ScResId(SCSTR_UNDO_GRAFFILTER);
125  pView->BegUndo( aStr );
126  pFilteredObj->SetGraphicObject( aFilterObj );
127  pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
128  pView->EndUndo();
129  }
130  }
131  }
132  }
133 
134  Invalidate();
135 }
136 
138 {
139  ScDrawView* pView = GetViewData().GetScDrawView();
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 
152  bEnable = false;
153 
154  if( !bEnable )
155  rSet.DisableItem( SID_EXTERNAL_EDIT );
156 }
157 
158 void ScGraphicShell::ExecuteExternalEdit( SAL_UNUSED_PARAMETER SfxRequest& )
159 {
160  ScDrawView* pView = GetViewData().GetScDrawView();
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, pObj));
173  m_ExternalEdits.back()->Edit( &aGraphicObject );
174  }
175  }
176 
177  Invalidate();
178 }
179 
181 {
182  ScDrawView* pView = GetViewData().GetScDrawView();
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 {
200  ScDrawView* pView = GetViewData().GetScDrawView();
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  {
213  SdrGrafObj* pNewObject = dialog.GetCompressedSdrGrafObj();
214  SdrPageView* pPageView = pView->GetSdrPageView();
215  OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Compress";
216  pView->BegUndo( aUndoString );
217  pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
218  pView->EndUndo();
219  }
220  }
221  }
222 
223  Invalidate();
224 }
225 
227 {
228  ScDrawView* pView = GetViewData().GetScDrawView();
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 
244 void ScGraphicShell::ExecuteCropGraphic( SAL_UNUSED_PARAMETER SfxRequest& )
245 {
246  ScDrawView* pView = GetViewData().GetScDrawView();
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 
264 void ScGraphicShell::ExecuteSaveGraphic( SAL_UNUSED_PARAMETER SfxRequest& /*rReq*/)
265 {
266  ScDrawView* pView = GetViewData().GetScDrawView();
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  {
281  nState = GraphicHelper::HasToSaveTransformedImage(pWinFrame);
282  }
283  }
284  else
285  {
286  nState = RET_NO;
287  }
288 
289  if (nState == RET_YES)
290  {
291  GraphicHelper::ExportGraphic(pWinFrame, pObj->GetTransformedGraphic(), "");
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 {
306  ScDrawView* pView = GetViewData().GetScDrawView();
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 
319  bEnable = false;
320 
321  if( !bEnable )
322  rSet.DisableItem( SID_SAVE_GRAPHIC );
323 }
324 
325 void ScGraphicShell::ExecuteChangePicture( SAL_UNUSED_PARAMETER SfxRequest& /*rReq*/)
326 {
327  ScDrawView* pView = GetViewData().GetScDrawView();
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  SdrGrafObj* pNewObject(pGraphicObj->CloneSdrObject(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 );
352  pView->EndUndo();
353  }
354  }
355  }
356  }
357 
358  Invalidate();
359 }
360 
362 {
363  ScDrawView* pView = GetViewData().GetScDrawView();
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: */
void ExecuteCompressGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:198
static short HasToSaveTransformedImage(weld::Widget *pWin)
size_t GetMarkCount() const
#define SFX_IMPL_INTERFACE(Class, SuperClass)
ScViewData & GetViewData()
Definition: drawsh.hxx:51
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:3075
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:89
SdrModel & getSdrModelFromSdrObject() const
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3063
void ExecuteFilter(const SfxRequest &rReq)
Definition: graphsh.cxx:102
void SetName(const OUString &rName)
#define SFX_OBJECTBAR_OBJECT
bool isExportLocked() const
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:158
std::vector< std::unique_ptr< SdrExternalToolEdit > > m_ExternalEdits
Definition: graphsh.hxx:40
void GetExternalEditState(SfxItemSet &rSet)
Definition: graphsh.cxx:137
#define ERRCODE_NONE
static void ExecuteGrafAttr(SfxRequest &rReq, SdrView &rView)
void ExecuteChangePicture(SfxRequest &rReq)
Definition: graphsh.cxx:325
virtual void Invalidate(sal_uInt16 nId=0)
RET_OK
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
void GetSaveGraphicState(SfxItemSet &rSet)
Definition: graphsh.cxx:304
void GetChangePictureState(SfxItemSet &rSet)
Definition: graphsh.cxx:361
void SetDragMode(SdrDragMode eMode)
void GetCropGraphicState(SfxItemSet &rSet)
Definition: graphsh.cxx:226
void ExecuteCropGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:244
SdrPageView * GetSdrPageView() const
void Execute(SfxRequest &rReq)
Definition: graphsh.cxx:72
void ExecuteSaveGraphic(SfxRequest &rReq)
Definition: graphsh.cxx:264
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:180
virtual SfxObjectShell * GetObjectShell()
ScGraphicShell(ScViewData &rData)
Definition: graphsh.cxx:53
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo