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 <svl/whiter.hxx>
24 : #include <svx/svdograf.hxx>
25 : #include <svx/grfflt.hxx>
26 : #include <svx/grafctrl.hxx>
27 : #include <svx/compressgraphicdialog.hxx>
28 : #include <vcl/msgbox.hxx>
29 :
30 : #include "graphsh.hxx"
31 : #include "sc.hrc"
32 : #include "viewdata.hxx"
33 : #include "drawview.hxx"
34 : #include "scresid.hxx"
35 : #include <svx/extedit.hxx>
36 :
37 : #define ScGraphicShell
38 : #include "scslots.hxx"
39 :
40 : #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
41 :
42 0 : class ScExternalToolEdit : public ExternalToolEdit
43 : {
44 : FmFormView* m_pView;
45 : SdrObject* m_pObj;
46 :
47 : public:
48 0 : ScExternalToolEdit ( FmFormView* pView, SdrObject* pObj ) :
49 : m_pView (pView),
50 0 : m_pObj (pObj)
51 0 : {}
52 :
53 0 : virtual void Update( Graphic& aGraphic )
54 : {
55 0 : SdrPageView* pPageView = m_pView->GetSdrPageView();
56 0 : if( pPageView )
57 : {
58 0 : SdrGrafObj* pNewObj = (SdrGrafObj*) m_pObj->Clone();
59 0 : String aStr( m_pView->GetDescriptionOfMarkedObjects() );
60 0 : aStr.Append( sal_Unicode(' ') );
61 0 : aStr.Append( String( "External Edit" ) );
62 0 : m_pView->BegUndo( aStr );
63 0 : pNewObj->SetGraphicObject( aGraphic );
64 0 : m_pView->ReplaceObjectAtView( m_pObj, *pPageView, pNewObj );
65 0 : m_pView->EndUndo();
66 : }
67 0 : }
68 : };
69 :
70 25 : SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
71 : {
72 10 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
73 5 : ScResId(RID_GRAPHIC_OBJECTBAR) );
74 5 : SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_GRAPHIC) );
75 5 : }
76 :
77 0 : TYPEINIT1( ScGraphicShell, ScDrawShell );
78 :
79 0 : ScGraphicShell::ScGraphicShell(ScViewData* pData) :
80 0 : ScDrawShell(pData)
81 : {
82 0 : SetHelpId(HID_SCSHELL_GRAPHIC);
83 0 : SetName(rtl::OUString("GraphicObject"));
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 15 : }
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|