Line data Source code
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/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>
30 :
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>
37 :
38 : #define ScGraphicShell
39 : #include "scslots.hxx"
40 :
41 0 : class ScExternalToolEdit : public ExternalToolEdit
42 : {
43 : FmFormView* m_pView;
44 : SdrObject* m_pObj;
45 :
46 : public:
47 0 : ScExternalToolEdit ( FmFormView* pView, SdrObject* pObj ) :
48 : m_pView (pView),
49 0 : m_pObj (pObj)
50 0 : {}
51 :
52 0 : virtual void Update( Graphic& aGraphic )
53 : {
54 0 : SdrPageView* pPageView = m_pView->GetSdrPageView();
55 0 : if( pPageView )
56 : {
57 0 : SdrGrafObj* pNewObj = (SdrGrafObj*) m_pObj->Clone();
58 0 : String aStr( m_pView->GetDescriptionOfMarkedObjects() );
59 0 : aStr.Append( sal_Unicode(' ') );
60 0 : aStr.Append( String( "External Edit" ) );
61 0 : m_pView->BegUndo( aStr );
62 0 : pNewObj->SetGraphicObject( aGraphic );
63 0 : m_pView->ReplaceObjectAtView( m_pObj, *pPageView, pNewObj );
64 0 : m_pView->EndUndo();
65 : }
66 0 : }
67 : };
68 :
69 155 : SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
70 : {
71 62 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
72 31 : ScResId(RID_GRAPHIC_OBJECTBAR) );
73 31 : SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_GRAPHIC) );
74 31 : }
75 :
76 0 : TYPEINIT1( ScGraphicShell, ScDrawShell );
77 :
78 0 : ScGraphicShell::ScGraphicShell(ScViewData* pData) :
79 0 : ScDrawShell(pData)
80 : {
81 0 : SetHelpId(HID_SCSHELL_GRAPHIC);
82 0 : SetName(OUString("GraphicObject"));
83 0 : SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
84 0 : }
85 :
86 0 : ScGraphicShell::~ScGraphicShell()
87 : {
88 0 : }
89 :
90 0 : void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
91 : {
92 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
93 :
94 0 : if( pView )
95 0 : SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
96 0 : }
97 :
98 0 : void ScGraphicShell::Execute( SfxRequest& rReq )
99 : {
100 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
101 :
102 0 : if( pView )
103 : {
104 0 : SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
105 0 : Invalidate();
106 : }
107 0 : }
108 :
109 0 : void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
110 : {
111 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
112 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
113 0 : sal_Bool bEnable = false;
114 :
115 0 : if( rMarkList.GetMarkCount() == 1 )
116 : {
117 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
118 :
119 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
120 0 : bEnable = sal_True;
121 : }
122 :
123 0 : if( !bEnable )
124 0 : SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
125 0 : }
126 :
127 0 : void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
128 : {
129 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
130 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
131 :
132 0 : if( rMarkList.GetMarkCount() == 1 )
133 : {
134 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
135 :
136 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
137 : {
138 0 : GraphicObject aFilterObj( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
139 :
140 0 : if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
141 0 : SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
142 : {
143 0 : SdrPageView* pPageView = pView->GetSdrPageView();
144 :
145 0 : if( pPageView )
146 : {
147 0 : SdrGrafObj* pFilteredObj = (SdrGrafObj*) pObj->Clone();
148 0 : String aStr( pView->GetDescriptionOfMarkedObjects() );
149 :
150 0 : aStr.Append( sal_Unicode(' ') );
151 0 : aStr.Append( String( ScResId( SCSTR_UNDO_GRAFFILTER ) ) );
152 0 : pView->BegUndo( aStr );
153 0 : pFilteredObj->SetGraphicObject( aFilterObj );
154 0 : pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
155 0 : pView->EndUndo();
156 : }
157 0 : }
158 : }
159 : }
160 :
161 0 : Invalidate();
162 0 : }
163 :
164 0 : void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
165 : {
166 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
167 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
168 0 : bool bEnable = false;
169 0 : if( rMarkList.GetMarkCount() == 1 )
170 : {
171 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
172 :
173 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
174 0 : bEnable = true;
175 : }
176 :
177 0 : if( !bEnable )
178 0 : rSet.DisableItem( SID_EXTERNAL_EDIT );
179 0 : }
180 :
181 0 : void ScGraphicShell::ExecuteExternalEdit( SfxRequest& )
182 : {
183 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
184 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
185 :
186 0 : if( rMarkList.GetMarkCount() == 1 )
187 : {
188 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
189 :
190 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
191 : {
192 0 : GraphicObject aGraphicObject( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
193 0 : ScExternalToolEdit* aExternalToolEdit = new ScExternalToolEdit( pView, pObj );
194 0 : aExternalToolEdit->Edit( &aGraphicObject );
195 : }
196 : }
197 :
198 0 : Invalidate();
199 0 : }
200 :
201 0 : void ScGraphicShell::GetCompressGraphicState( SfxItemSet& rSet )
202 : {
203 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
204 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
205 0 : bool bEnable = false;
206 0 : if( rMarkList.GetMarkCount() == 1 )
207 : {
208 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
209 :
210 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
211 0 : bEnable = true;
212 : }
213 :
214 0 : if( !bEnable )
215 0 : rSet.DisableItem( SID_COMPRESS_GRAPHIC );
216 0 : }
217 :
218 0 : void ScGraphicShell::ExecuteCompressGraphic( SfxRequest& )
219 : {
220 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
221 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
222 :
223 0 : if( rMarkList.GetMarkCount() == 1 )
224 : {
225 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
226 :
227 0 : if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
228 : {
229 0 : SdrGrafObj* pGraphicObj = (SdrGrafObj*) pObj;
230 0 : CompressGraphicsDialog dialog( GetViewData()->GetDialogParent(), pGraphicObj, GetViewData()->GetBindings() );
231 0 : if ( dialog.Execute() == RET_OK )
232 : {
233 0 : SdrGrafObj* pNewObject = dialog.GetCompressedSdrGrafObj();
234 0 : SdrPageView* pPageView = pView->GetSdrPageView();
235 0 : String aUndoString( pView->GetDescriptionOfMarkedObjects() );
236 0 : aUndoString += String( " Compress" );
237 0 : pView->BegUndo( aUndoString );
238 0 : pView->ReplaceObjectAtView( pObj, *pPageView, pNewObject );
239 0 : pView->EndUndo();
240 0 : }
241 : }
242 : }
243 :
244 0 : Invalidate();
245 93 : }
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|