fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / graphsh.cxx
blob94742a0a177caa8d7847f2e4124e6df315bf92fd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/app.hxx>
21 #include <sfx2/objface.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/sidebar/EnumContext.hxx>
24 #include <sfx2/opengrf.hxx>
25 #include <svl/whiter.hxx>
26 #include <svx/svdograf.hxx>
27 #include <svx/grfflt.hxx>
28 #include <svx/grafctrl.hxx>
29 #include <svx/compressgraphicdialog.hxx>
30 #include <svx/graphichelper.hxx>
31 #include <vcl/msgbox.hxx>
33 #include "graphsh.hxx"
34 #include "sc.hrc"
35 #include "viewdata.hxx"
36 #include "drawview.hxx"
37 #include "scresid.hxx"
38 #include <svx/extedit.hxx>
39 #include "tabvwsh.hxx"
41 #define ScGraphicShell
42 #include "scslots.hxx"
44 SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell)
46 void ScGraphicShell::InitInterface_Impl()
48 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
49 RID_GRAPHIC_OBJECTBAR);
51 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_GRAPHIC));
54 TYPEINIT1( ScGraphicShell, ScDrawShell );
56 ScGraphicShell::ScGraphicShell(ScViewData* pData) :
57 ScDrawShell(pData)
59 SetHelpId(HID_SCSHELL_GRAPHIC);
60 SetName(OUString("GraphicObject"));
61 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
64 ScGraphicShell::~ScGraphicShell()
68 void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
70 ScDrawView* pView = GetViewData()->GetScDrawView();
72 if( pView )
73 SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
76 void ScGraphicShell::Execute( SfxRequest& rReq )
78 ScDrawView* pView = GetViewData()->GetScDrawView();
80 if( pView )
82 SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
83 Invalidate();
87 void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
89 ScDrawView* pView = GetViewData()->GetScDrawView();
90 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
91 bool bEnable = false;
93 if( rMarkList.GetMarkCount() == 1 )
95 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
97 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
98 bEnable = true;
101 if( !bEnable )
102 SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
105 void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
107 ScDrawView* pView = GetViewData()->GetScDrawView();
108 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
110 if( rMarkList.GetMarkCount() == 1 )
112 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
114 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
116 GraphicObject aFilterObj( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
118 if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
119 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
121 SdrPageView* pPageView = pView->GetSdrPageView();
123 if( pPageView )
125 SdrGrafObj* pFilteredObj = static_cast<SdrGrafObj*>(pObj->Clone());
126 OUString aStr = pView->GetDescriptionOfMarkedObjects() + " " + OUString(ScResId( SCSTR_UNDO_GRAFFILTER ));
127 pView->BegUndo( aStr );
128 pFilteredObj->SetGraphicObject( aFilterObj );
129 pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
130 pView->EndUndo();
136 Invalidate();
139 void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
141 ScDrawView* pView = GetViewData()->GetScDrawView();
142 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
143 bool bEnable = false;
144 if( rMarkList.GetMarkCount() == 1 )
146 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
148 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
149 bEnable = true;
152 if( !bEnable )
153 rSet.DisableItem( SID_EXTERNAL_EDIT );
156 void ScGraphicShell::ExecuteExternalEdit( SfxRequest& )
158 ScDrawView* pView = GetViewData()->GetScDrawView();
159 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
161 if( rMarkList.GetMarkCount() == 1 )
163 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
165 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
167 GraphicObject aGraphicObject( static_cast<SdrGrafObj*>(pObj)->GetGraphicObject() );
168 m_ExternalEdits.push_back( std::unique_ptr<SdrExternalToolEdit>(
169 new SdrExternalToolEdit(pView, pObj)));
170 m_ExternalEdits.back()->Edit( &aGraphicObject );
174 Invalidate();
177 void ScGraphicShell::GetCompressGraphicState( SfxItemSet& rSet )
179 ScDrawView* pView = GetViewData()->GetScDrawView();
180 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
181 bool bEnable = false;
182 if( rMarkList.GetMarkCount() == 1 )
184 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
186 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
187 bEnable = true;
190 if( !bEnable )
191 rSet.DisableItem( SID_COMPRESS_GRAPHIC );
194 void ScGraphicShell::ExecuteCompressGraphic( SfxRequest& )
196 ScDrawView* pView = GetViewData()->GetScDrawView();
197 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
199 if( rMarkList.GetMarkCount() == 1 )
201 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
203 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
205 SdrGrafObj* pGraphicObj = static_cast<SdrGrafObj*>(pObj);
206 ScopedVclPtrInstance< CompressGraphicsDialog > dialog( GetViewData()->GetDialogParent(), pGraphicObj, GetViewData()->GetBindings() );
207 if ( dialog->Execute() == RET_OK )
209 SdrGrafObj* pNewObject = dialog->GetCompressedSdrGrafObj();
210 SdrPageView* pPageView = pView->GetSdrPageView();
211 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Compress";
212 pView->BegUndo( aUndoString );
213 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
214 pView->EndUndo();
219 Invalidate();
222 void ScGraphicShell::GetCropGraphicState( SfxItemSet& rSet )
224 ScDrawView* pView = GetViewData()->GetScDrawView();
225 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
226 bool bEnable = false;
227 if( rMarkList.GetMarkCount() == 1 )
229 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
231 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
232 bEnable = true;
235 if( !bEnable )
236 rSet.DisableItem( SID_OBJECT_CROP );
239 void ScGraphicShell::ExecuteCropGraphic( SfxRequest& )
241 ScDrawView* pView = GetViewData()->GetScDrawView();
242 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
244 if( rMarkList.GetMarkCount() == 1 )
246 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
248 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
250 pView->SetEditMode(SDREDITMODE_EDIT);
251 pView->SetDragMode(SDRDRAG_CROP);
255 Invalidate();
258 void ScGraphicShell::ExecuteSaveGraphic(SfxRequest& /*rReq*/)
260 ScDrawView* pView = GetViewData()->GetScDrawView();
261 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
262 if( rMarkList.GetMarkCount() == 1 )
264 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
265 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
267 GraphicObject aGraphicObject( static_cast<SdrGrafObj*>( pObj )->GetGraphicObject() );
269 GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), "" );
274 Invalidate();
277 void ScGraphicShell::GetSaveGraphicState(SfxItemSet &rSet)
279 ScDrawView* pView = GetViewData()->GetScDrawView();
280 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
281 bool bEnable = false;
282 if( rMarkList.GetMarkCount() == 1 )
284 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
286 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
287 bEnable = true;
290 if( !bEnable )
291 rSet.DisableItem( SID_SAVE_GRAPHIC );
294 void ScGraphicShell::ExecuteChangePicture(SfxRequest& /*rReq*/)
296 ScDrawView* pView = GetViewData()->GetScDrawView();
297 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
299 if( rMarkList.GetMarkCount() == 1 )
301 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
303 if( pObj && pObj->ISA( SdrGrafObj ) && static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP )
305 SdrGrafObj* pGraphicObj = static_cast<SdrGrafObj*>(pObj);
306 SvxOpenGraphicDialog aDlg(ScResId(STR_INSERTGRAPHIC));
308 if( aDlg.Execute() == GRFILTER_OK )
310 Graphic aGraphic;
311 int nError = aDlg.GetGraphic(aGraphic);
312 if( nError == GRFILTER_OK )
314 SdrGrafObj* pNewObject = pGraphicObj->Clone();
315 pNewObject->SetGraphic( aGraphic );
316 SdrPageView* pPageView = pView->GetSdrPageView();
317 OUString aUndoString = pView->GetDescriptionOfMarkedObjects() + " Change";
318 pView->BegUndo( aUndoString );
319 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
320 pView->EndUndo();
326 Invalidate();
329 void ScGraphicShell::GetChangePictureState(SfxItemSet &rSet)
331 ScDrawView* pView = GetViewData()->GetScDrawView();
332 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
333 bool bEnable = false;
334 if( rMarkList.GetMarkCount() == 1 )
336 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
338 if( pObj && pObj->ISA( SdrGrafObj ) && ( static_cast<SdrGrafObj*>(pObj)->GetGraphicType() == GRAPHIC_BITMAP ) )
339 bEnable = true;
342 if( !bEnable )
343 rSet.DisableItem( SID_CHANGE_PICTURE );
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */