1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
47 ScExternalToolEdit ( FmFormView
* pView
, SdrObject
* pObj
) :
52 virtual void Update( Graphic
& aGraphic
)
54 SdrPageView
* pPageView
= m_pView
->GetSdrPageView();
57 SdrGrafObj
* pNewObj
= (SdrGrafObj
*) m_pObj
->Clone();
58 OUString aStr
= m_pView
->GetDescriptionOfMarkedObjects() + " External Edit";
59 m_pView
->BegUndo( aStr
);
60 pNewObj
->SetGraphicObject( aGraphic
);
61 m_pView
->ReplaceObjectAtView( m_pObj
, *pPageView
, pNewObj
);
67 SFX_IMPL_INTERFACE(ScGraphicShell
, ScDrawShell
, ScResId(SCSTR_GRAPHICSHELL
) )
69 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
70 ScResId(RID_GRAPHIC_OBJECTBAR
) );
71 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_GRAPHIC
) );
74 TYPEINIT1( ScGraphicShell
, ScDrawShell
);
76 ScGraphicShell::ScGraphicShell(ScViewData
* pData
) :
79 SetHelpId(HID_SCSHELL_GRAPHIC
);
80 SetName(OUString("GraphicObject"));
81 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic
));
84 ScGraphicShell::~ScGraphicShell()
88 void ScGraphicShell::GetAttrState( SfxItemSet
& rSet
)
90 ScDrawView
* pView
= GetViewData()->GetScDrawView();
93 SvxGrafAttrHelper::GetGrafAttrState( rSet
, *pView
);
96 void ScGraphicShell::Execute( SfxRequest
& rReq
)
98 ScDrawView
* pView
= GetViewData()->GetScDrawView();
102 SvxGrafAttrHelper::ExecuteGrafAttr( rReq
, *pView
);
107 void ScGraphicShell::GetFilterState( SfxItemSet
& rSet
)
109 ScDrawView
* pView
= GetViewData()->GetScDrawView();
110 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
111 sal_Bool bEnable
= false;
113 if( rMarkList
.GetMarkCount() == 1 )
115 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
117 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
) )
122 SvxGraphicFilter::DisableGraphicFilterSlots( rSet
);
125 void ScGraphicShell::ExecuteFilter( SfxRequest
& rReq
)
127 ScDrawView
* pView
= GetViewData()->GetScDrawView();
128 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
130 if( rMarkList
.GetMarkCount() == 1 )
132 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
134 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
)
136 GraphicObject
aFilterObj( ( (SdrGrafObj
*) pObj
)->GetGraphicObject() );
138 if( SVX_GRAPHICFILTER_ERRCODE_NONE
==
139 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq
, aFilterObj
) )
141 SdrPageView
* pPageView
= pView
->GetSdrPageView();
145 SdrGrafObj
* pFilteredObj
= (SdrGrafObj
*) pObj
->Clone();
146 OUString aStr
= pView
->GetDescriptionOfMarkedObjects() + " " + OUString(ScResId( SCSTR_UNDO_GRAFFILTER
));
147 pView
->BegUndo( aStr
);
148 pFilteredObj
->SetGraphicObject( aFilterObj
);
149 pView
->ReplaceObjectAtView( pObj
, *pPageView
, pFilteredObj
);
159 void ScGraphicShell::GetExternalEditState( SfxItemSet
& rSet
)
161 ScDrawView
* pView
= GetViewData()->GetScDrawView();
162 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
163 bool bEnable
= false;
164 if( rMarkList
.GetMarkCount() == 1 )
166 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
168 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
) )
173 rSet
.DisableItem( SID_EXTERNAL_EDIT
);
176 void ScGraphicShell::ExecuteExternalEdit( SfxRequest
& )
178 ScDrawView
* pView
= GetViewData()->GetScDrawView();
179 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
181 if( rMarkList
.GetMarkCount() == 1 )
183 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
185 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
)
187 GraphicObject
aGraphicObject( ( (SdrGrafObj
*) pObj
)->GetGraphicObject() );
188 ScExternalToolEdit
* aExternalToolEdit
= new ScExternalToolEdit( pView
, pObj
);
189 aExternalToolEdit
->Edit( &aGraphicObject
);
196 void ScGraphicShell::GetCompressGraphicState( SfxItemSet
& rSet
)
198 ScDrawView
* pView
= GetViewData()->GetScDrawView();
199 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
200 bool bEnable
= false;
201 if( rMarkList
.GetMarkCount() == 1 )
203 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
205 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
) )
210 rSet
.DisableItem( SID_COMPRESS_GRAPHIC
);
213 void ScGraphicShell::ExecuteCompressGraphic( SfxRequest
& )
215 ScDrawView
* pView
= GetViewData()->GetScDrawView();
216 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
218 if( rMarkList
.GetMarkCount() == 1 )
220 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
222 if( pObj
&& pObj
->ISA( SdrGrafObj
) && ( (SdrGrafObj
*) pObj
)->GetGraphicType() == GRAPHIC_BITMAP
)
224 SdrGrafObj
* pGraphicObj
= (SdrGrafObj
*) pObj
;
225 CompressGraphicsDialog
dialog( GetViewData()->GetDialogParent(), pGraphicObj
, GetViewData()->GetBindings() );
226 if ( dialog
.Execute() == RET_OK
)
228 SdrGrafObj
* pNewObject
= dialog
.GetCompressedSdrGrafObj();
229 SdrPageView
* pPageView
= pView
->GetSdrPageView();
230 OUString aUndoString
= pView
->GetDescriptionOfMarkedObjects() + " Compress";
231 pView
->BegUndo( aUndoString
);
232 pView
->ReplaceObjectAtView( pObj
, *pPageView
, pNewObject
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */