bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / drawfunc / graphsh.cxx
blob6276575cd7125c595e199a2e71727e7e36d65ea4
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 <svl/whiter.hxx>
25 #include <svx/svdograf.hxx>
26 #include <svx/grfflt.hxx>
27 #include <svx/grafctrl.hxx>
28 #include <svx/compressgraphicdialog.hxx>
29 #include <vcl/msgbox.hxx>
31 #include "graphsh.hxx"
32 #include "sc.hrc"
33 #include "viewdata.hxx"
34 #include "drawview.hxx"
35 #include "scresid.hxx"
36 #include <svx/extedit.hxx>
38 #define ScGraphicShell
39 #include "scslots.hxx"
41 class ScExternalToolEdit : public ExternalToolEdit
43 FmFormView* m_pView;
44 SdrObject* m_pObj;
46 public:
47 ScExternalToolEdit ( FmFormView* pView, SdrObject* pObj ) :
48 m_pView (pView),
49 m_pObj (pObj)
52 virtual void Update( Graphic& aGraphic )
54 SdrPageView* pPageView = m_pView->GetSdrPageView();
55 if( pPageView )
57 SdrGrafObj* pNewObj = (SdrGrafObj*) m_pObj->Clone();
58 String aStr( m_pView->GetDescriptionOfMarkedObjects() );
59 aStr.Append( sal_Unicode(' ') );
60 aStr.Append( String( "External Edit" ) );
61 m_pView->BegUndo( aStr );
62 pNewObj->SetGraphicObject( aGraphic );
63 m_pView->ReplaceObjectAtView( m_pObj, *pPageView, pNewObj );
64 m_pView->EndUndo();
69 SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
71 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
72 ScResId(RID_GRAPHIC_OBJECTBAR) );
73 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_GRAPHIC) );
76 TYPEINIT1( ScGraphicShell, ScDrawShell );
78 ScGraphicShell::ScGraphicShell(ScViewData* pData) :
79 ScDrawShell(pData)
81 SetHelpId(HID_SCSHELL_GRAPHIC);
82 SetName(OUString("GraphicObject"));
83 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
86 ScGraphicShell::~ScGraphicShell()
90 void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
92 ScDrawView* pView = GetViewData()->GetScDrawView();
94 if( pView )
95 SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
98 void ScGraphicShell::Execute( SfxRequest& rReq )
100 ScDrawView* pView = GetViewData()->GetScDrawView();
102 if( pView )
104 SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
105 Invalidate();
109 void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
111 ScDrawView* pView = GetViewData()->GetScDrawView();
112 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
113 sal_Bool bEnable = false;
115 if( rMarkList.GetMarkCount() == 1 )
117 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
119 if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
120 bEnable = sal_True;
123 if( !bEnable )
124 SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
127 void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
129 ScDrawView* pView = GetViewData()->GetScDrawView();
130 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
132 if( rMarkList.GetMarkCount() == 1 )
134 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
136 if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
138 GraphicObject aFilterObj( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
140 if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
141 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
143 SdrPageView* pPageView = pView->GetSdrPageView();
145 if( pPageView )
147 SdrGrafObj* pFilteredObj = (SdrGrafObj*) pObj->Clone();
148 String aStr( pView->GetDescriptionOfMarkedObjects() );
150 aStr.Append( sal_Unicode(' ') );
151 aStr.Append( String( ScResId( SCSTR_UNDO_GRAFFILTER ) ) );
152 pView->BegUndo( aStr );
153 pFilteredObj->SetGraphicObject( aFilterObj );
154 pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
155 pView->EndUndo();
161 Invalidate();
164 void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
166 ScDrawView* pView = GetViewData()->GetScDrawView();
167 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
168 bool bEnable = false;
169 if( rMarkList.GetMarkCount() == 1 )
171 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
173 if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
174 bEnable = true;
177 if( !bEnable )
178 rSet.DisableItem( SID_EXTERNAL_EDIT );
181 void ScGraphicShell::ExecuteExternalEdit( SfxRequest& )
183 ScDrawView* pView = GetViewData()->GetScDrawView();
184 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
186 if( rMarkList.GetMarkCount() == 1 )
188 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
190 if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
192 GraphicObject aGraphicObject( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
193 ScExternalToolEdit* aExternalToolEdit = new ScExternalToolEdit( pView, pObj );
194 aExternalToolEdit->Edit( &aGraphicObject );
198 Invalidate();
201 void ScGraphicShell::GetCompressGraphicState( SfxItemSet& rSet )
203 ScDrawView* pView = GetViewData()->GetScDrawView();
204 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
205 bool bEnable = false;
206 if( rMarkList.GetMarkCount() == 1 )
208 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
210 if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
211 bEnable = true;
214 if( !bEnable )
215 rSet.DisableItem( SID_COMPRESS_GRAPHIC );
218 void ScGraphicShell::ExecuteCompressGraphic( SfxRequest& )
220 ScDrawView* pView = GetViewData()->GetScDrawView();
221 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
223 if( rMarkList.GetMarkCount() == 1 )
225 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
227 if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
229 SdrGrafObj* pGraphicObj = (SdrGrafObj*) pObj;
230 CompressGraphicsDialog dialog( GetViewData()->GetDialogParent(), pGraphicObj, GetViewData()->GetBindings() );
231 if ( dialog.Execute() == RET_OK )
233 SdrGrafObj* pNewObject = dialog.GetCompressedSdrGrafObj();
234 SdrPageView* pPageView = pView->GetSdrPageView();
235 String aUndoString( pView->GetDescriptionOfMarkedObjects() );
236 aUndoString += String( " Compress" );
237 pView->BegUndo( aUndoString );
238 pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
239 pView->EndUndo();
244 Invalidate();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */