LibreOffice Module svx (master) 1
grfflt.cxx
Go to the documentation of this file.
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
24
25#include <sfx2/viewfrm.hxx>
26#include <sfx2/viewsh.hxx>
27#include <sfx2/objsh.hxx>
28#include <sfx2/request.hxx>
29
30#include <osl/diagnose.h>
31#include <svx/grfflt.hxx>
32#include <svx/svxids.hrc>
33#include <svx/svxdlg.hxx>
34
35
37{
38 const Graphic& rGraphic = rFilterObject.GetGraphic();
40
41 if( rGraphic.GetType() == GraphicType::Bitmap )
42 {
43 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
44 SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr;
45 weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr;
46 Graphic aGraphic;
47
48 switch( rReq.GetSlot() )
49 {
50 case SID_GRFFILTER_INVERT:
51 {
52 if( pShell )
53 pShell->SetWaitCursor( true );
54
55 if( rGraphic.IsAnimated() )
56 {
57 Animation aAnimation( rGraphic.GetAnimation() );
58
59 if( aAnimation.Invert() )
60 aGraphic = aAnimation;
61 }
62 else
63 {
64 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
65
66 if( aBmpEx.Invert() )
67 aGraphic = aBmpEx;
68 }
69
70 if( pShell )
71 pShell->SetWaitCursor( false );
72 }
73 break;
74
75 case SID_GRFFILTER_SMOOTH:
76 {
78 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSmooth(pFrameWeld, rGraphic, 0.7));
79 if( aDlg->Execute() == RET_OK )
80 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
81 }
82 break;
83
84 case SID_GRFFILTER_SHARPEN:
85 {
86 if( pShell )
87 pShell->SetWaitCursor( true );
88
89 if( rGraphic.IsAnimated() )
90 {
91 Animation aAnimation( rGraphic.GetAnimation() );
92
94 aGraphic = aAnimation;
95 }
96 else
97 {
98 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
99
101 aGraphic = aBmpEx;
102 }
103
104 if( pShell )
105 pShell->SetWaitCursor( false );
106 }
107 break;
108
109 case SID_GRFFILTER_REMOVENOISE:
110 {
111 if( pShell )
112 pShell->SetWaitCursor( true );
113
114 if( rGraphic.IsAnimated() )
115 {
116 Animation aAnimation( rGraphic.GetAnimation() );
117
118 if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter()))
119 aGraphic = aAnimation;
120 }
121 else
122 {
123 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
124
126 aGraphic = aBmpEx;
127 }
128
129 if( pShell )
130 pShell->SetWaitCursor( false );
131 }
132 break;
133
134 case SID_GRFFILTER_SOBEL:
135 {
136 if( pShell )
137 pShell->SetWaitCursor( true );
138
139 if( rGraphic.IsAnimated() )
140 {
141 Animation aAnimation( rGraphic.GetAnimation() );
142
144 aGraphic = aAnimation;
145 }
146 else
147 {
148 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
149
151 aGraphic = aBmpEx;
152 }
153
154 if( pShell )
155 pShell->SetWaitCursor( false );
156 }
157 break;
158
159 case SID_GRFFILTER_MOSAIC:
160 {
163 if( aDlg->Execute() == RET_OK )
164 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
165 }
166 break;
167
168 case SID_GRFFILTER_EMBOSS:
169 {
172 if( aDlg->Execute() == RET_OK )
173 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
174 }
175 break;
176
177 case SID_GRFFILTER_POSTER:
178 {
181 if( aDlg->Execute() == RET_OK )
182 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
183 }
184 break;
185
186 case SID_GRFFILTER_POPART:
187 {
188 if( pShell )
189 pShell->SetWaitCursor( true );
190
191 if( rGraphic.IsAnimated() )
192 {
193 Animation aAnimation( rGraphic.GetAnimation() );
194
195 if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter()))
196 aGraphic = aAnimation;
197 }
198 else
199 {
200 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
201
203 aGraphic = aBmpEx;
204 }
205
206 if( pShell )
207 pShell->SetWaitCursor( false );
208 }
209 break;
210
211 case SID_GRFFILTER_SEPIA:
212 {
215 if( aDlg->Execute() == RET_OK )
216 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
217 }
218 break;
219
220 case SID_GRFFILTER_SOLARIZE:
221 {
224 if( aDlg->Execute() == RET_OK )
225 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
226 }
227 break;
228
229 case SID_GRFFILTER :
230 {
231 // do nothing; no error
233 break;
234 }
235
236 default:
237 {
238 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
240 }
241 break;
242 }
243
244 if( aGraphic.GetType() != GraphicType::NONE )
245 {
246 rFilterObject.SetGraphic( aGraphic );
248 }
249 }
250
251 return nRet;
252}
253
254
256{
257 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER ) )
258 rSet.DisableItem( SID_GRFFILTER );
259
260 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
261 rSet.DisableItem( SID_GRFFILTER_INVERT );
262
263 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
264 rSet.DisableItem( SID_GRFFILTER_SMOOTH );
265
266 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
267 rSet.DisableItem( SID_GRFFILTER_SHARPEN );
268
269 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
270 rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
271
272 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
273 rSet.DisableItem( SID_GRFFILTER_SOBEL );
274
275 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
276 rSet.DisableItem( SID_GRFFILTER_MOSAIC );
277
278 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
279 rSet.DisableItem( SID_GRFFILTER_EMBOSS );
280
281 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
282 rSet.DisableItem( SID_GRFFILTER_POSTER );
283
284 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
285 rSet.DisableItem( SID_GRFFILTER_POPART );
286
287 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
288 rSet.DisableItem( SID_GRFFILTER_SEPIA );
289
290 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
291 rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
292};
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Invert()
bool Invert()
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
void SetGraphic(const Graphic &rGraphic)
const Graphic & GetGraphic() const
Animation GetAnimation() const
GraphicType GetType() const
bool IsAnimated() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void DisableItem(sal_uInt16 nWhich)
void SetWaitCursor(bool bSet) const
sal_uInt16 GetSlot() const
SfxViewShell * GetViewShell() const
static SfxViewFrame * Current()
virtual SfxObjectShell * GetObjectShell() override
weld::Window * GetFrameWeld() const
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterSmooth(weld::Window *pParent, const Graphic &rGraphic, double nRadius)=0
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterPoster(weld::Window *pParent, const Graphic &rGraphic)=0
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterMosaic(weld::Window *pParent, const Graphic &rGraphic)=0
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterSolarize(weld::Window *pParent, const Graphic &rGraphic)=0
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterEmboss(weld::Window *pParent, const Graphic &rGraphic)=0
static SvxAbstractDialogFactory * Create()
Definition: svxdlg.cxx:22
virtual VclPtr< AbstractGraphicFilterDialog > CreateGraphicFilterSepia(weld::Window *pParent, const Graphic &rGraphic)=0
static SvxGraphicFilterResult ExecuteGrfFilterSlot(SfxRequest const &rReq, GraphicObject &rFilterObject)
Definition: grfflt.cxx:36
static void DisableGraphicFilterSlots(SfxItemSet &rSet)
Definition: grfflt.cxx:255
SvxGraphicFilterResult
Definition: grfflt.hxx:25
static SfxItemSet & rSet
RET_OK