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 <config_features.h>
22 #include <DrawViewShell.hxx>
23 #include <sfx2/request.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/weld.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <svx/svdograf.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/fontwork.hxx>
30 #include <svx/bmpmask.hxx>
31 #include <svx/imapdlg.hxx>
32 #include <svx/SvxColorChildWindow.hxx>
33 #include <svx/f3dchild.hxx>
34 #include <avmedia/mediaplayer.hxx>
35 #include <svl/intitem.hxx>
38 #include <strings.hrc>
40 #include <animobjs.hxx>
41 #include <AnimationChildWindow.hxx>
42 #include <sdresid.hxx>
43 #include <drawdoc.hxx>
44 #include <drawview.hxx>
45 #include <svx/svdoashp.hxx>
50 * handle SfxRequests for FontWork
52 void DrawViewShell::ExecFormText(SfxRequest
& rReq
)
54 // nothing is executed during a slide show!
55 if(HasCurrentFunction(SID_PRESENTATION
))
60 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
62 if ( rMarkList
.GetMarkCount() == 1 && rReq
.GetArgs() &&
63 !mpDrawView
->IsPresObjSelected() )
65 const SfxItemSet
& rSet
= *rReq
.GetArgs();
67 if ( mpDrawView
->IsTextEdit() )
68 mpDrawView
->SdrEndTextEdit();
70 mpDrawView
->SetAttributes(rSet
);
75 * Return state values for FontWork
77 void DrawViewShell::GetFormTextState(SfxItemSet
& rSet
)
79 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
80 const SdrObject
* pObj
= nullptr;
82 if ( rMarkList
.GetMarkCount() == 1 )
83 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
85 const SdrTextObj
* pTextObj
= DynCastSdrTextObj(pObj
);
86 const bool bDeactivate(
89 !pTextObj
->HasText() ||
90 dynamic_cast< const SdrObjCustomShape
* >(pObj
)); // #121538# no FontWork for CustomShapes
94 // automatic open/close the FontWork-Dialog; first deactivate it
96 rSet
.DisableItem(XATTR_FORMTXTSTYLE
);
97 rSet
.DisableItem(XATTR_FORMTXTADJUST
);
98 rSet
.DisableItem(XATTR_FORMTXTDISTANCE
);
99 rSet
.DisableItem(XATTR_FORMTXTSTART
);
100 rSet
.DisableItem(XATTR_FORMTXTMIRROR
);
101 rSet
.DisableItem(XATTR_FORMTXTHIDEFORM
);
102 rSet
.DisableItem(XATTR_FORMTXTOUTLINE
);
103 rSet
.DisableItem(XATTR_FORMTXTSHADOW
);
104 rSet
.DisableItem(XATTR_FORMTXTSHDWCOLOR
);
105 rSet
.DisableItem(XATTR_FORMTXTSHDWXVAL
);
106 rSet
.DisableItem(XATTR_FORMTXTSHDWYVAL
);
110 SfxItemSet
aSet( GetDoc()->GetPool() );
111 mpDrawView
->GetAttributes( aSet
);
116 void DrawViewShell::ExecAnimationWin( SfxRequest
& rReq
)
118 // nothing is executed during a slide show!
119 if (HasCurrentFunction(SID_PRESENTATION
))
124 sal_uInt16 nSId
= rReq
.GetSlot();
128 case SID_ANIMATOR_INIT
:
129 case SID_ANIMATOR_ADD
:
130 case SID_ANIMATOR_CREATE
:
132 AnimationWindow
* pAnimWin
;
133 sal_uInt16 nId
= AnimationChildWindow::GetChildWindowId();
135 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(nId
);
137 pAnimWin
= pWnd
? static_cast<AnimationWindow
*>(pWnd
->GetWindow()) : nullptr;
141 if( nSId
== SID_ANIMATOR_ADD
)
142 pAnimWin
->AddObj( *mpDrawView
);
143 else if( nSId
== SID_ANIMATOR_CREATE
)
144 pAnimWin
->CreateAnimObj( *mpDrawView
);
155 * Return status values for animator
157 * nValue == 0 -> No button
158 * nValue == 1 -> Button 'accept'
159 * nValue == 2 -> Button 'accept individually'
160 * nValue == 3 -> Buttons 'accept' and 'accept individually'
162 void DrawViewShell::GetAnimationWinState( SfxItemSet
& rSet
)
164 // here we could disable buttons etc.
167 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
168 const size_t nMarkCount
= rMarkList
.GetMarkCount();
170 if( nMarkCount
== 0 )
172 else if( nMarkCount
> 1 )
176 const SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
177 SdrInventor nInv
= pObj
->GetObjInventor();
178 SdrObjKind nId
= pObj
->GetObjIdentifier();
179 // 1 selected group object
180 if( nInv
== SdrInventor::Default
&& nId
== SdrObjKind::Group
)
182 else if( nInv
== SdrInventor::Default
&& nId
== SdrObjKind::Graphic
) // Animated GIF ?
184 sal_uInt16 nCount
= 0;
186 if( static_cast<const SdrGrafObj
*>(pObj
)->IsAnimated() )
187 nCount
= static_cast<const SdrGrafObj
*>(pObj
)->GetGraphic().GetAnimation().Count();
196 rSet
.Put( SfxUInt16Item( SID_ANIMATOR_STATE
, nValue
) );
199 void DrawViewShell::SetChildWindowState( SfxItemSet
& rSet
)
201 // State of SfxChild-Windows (Animator, Fontwork etc.)
202 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_FONTWORK
) )
204 sal_uInt16 nId
= SvxFontWorkChildWindow::GetChildWindowId();
205 rSet
.Put(SfxBoolItem(SID_FONTWORK
, GetViewFrame()->HasChildWindow(nId
)));
207 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_COLOR_CONTROL
) )
209 sal_uInt16 nId
= SvxColorChildWindow::GetChildWindowId();
210 rSet
.Put(SfxBoolItem(SID_COLOR_CONTROL
, GetViewFrame()->HasChildWindow(nId
)));
212 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_ANIMATION_OBJECTS
) )
214 sal_uInt16 nId
= AnimationChildWindow::GetChildWindowId();
215 rSet
.Put( SfxBoolItem( SID_ANIMATION_OBJECTS
, GetViewFrame()->HasChildWindow( nId
) ) );
217 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_NAVIGATOR
) )
219 rSet
.Put( SfxBoolItem( SID_NAVIGATOR
, GetViewFrame()->HasChildWindow( SID_NAVIGATOR
) ) );
221 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_BMPMASK
) )
223 sal_uInt16 nId
= SvxBmpMaskChildWindow::GetChildWindowId();
224 rSet
.Put( SfxBoolItem( SID_BMPMASK
, GetViewFrame()->HasChildWindow( nId
) ) );
226 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_IMAP
) )
228 sal_uInt16 nId
= SvxIMapDlgChildWindow::GetChildWindowId();
229 rSet
.Put( SfxBoolItem( SID_IMAP
, GetViewFrame()->HasChildWindow( nId
) ) );
231 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_3D_WIN
) )
233 sal_uInt16 nId
= Svx3DChildWindow::GetChildWindowId();
234 rSet
.Put( SfxBoolItem( SID_3D_WIN
, GetViewFrame()->HasChildWindow( nId
) ) );
236 #if HAVE_FEATURE_AVMEDIA
237 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_AVMEDIA_PLAYER
) )
239 sal_uInt16 nId
= ::avmedia::MediaPlayer::GetChildWindowId();
240 rSet
.Put( SfxBoolItem( SID_AVMEDIA_PLAYER
, GetViewFrame()->HasChildWindow( nId
) ) );
246 * Handle SfxRequests for pipette
248 void DrawViewShell::ExecBmpMask( SfxRequest
const & rReq
)
250 // nothing is executed during a slide show!
251 if (HasCurrentFunction(SID_PRESENTATION
))
254 switch ( rReq
.GetSlot() )
256 case SID_BMPMASK_PIPETTE
:
258 mbPipette
= rReq
.GetArgs()->Get( SID_BMPMASK_PIPETTE
).GetValue();
262 case SID_BMPMASK_EXEC
:
267 SdrGrafObj
* pObj
= nullptr;
268 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
269 if( rMarkList
.GetMarkCount() )
270 pObj
= dynamic_cast< SdrGrafObj
* >( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
272 if ( pObj
&& !mpDrawView
->IsTextEdit() )
274 rtl::Reference
<SdrGrafObj
> xNewObj(SdrObject::Clone(*pObj
, pObj
->getSdrModelFromSdrObject()));
277 if (xNewObj
->IsLinkedGraphic())
279 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), u
"modules/sdraw/ui/queryunlinkimagedialog.ui"_ustr
));
280 std::unique_ptr
<weld::MessageDialog
> xQueryBox(xBuilder
->weld_message_dialog(u
"QueryUnlinkImageDialog"_ustr
));
282 if (RET_YES
== xQueryBox
->run())
283 xNewObj
->ReleaseGraphicLink();
288 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(
289 SvxBmpMaskChildWindow::GetChildWindowId());
290 SvxBmpMask
* pBmpMask
= pWnd
? static_cast<SvxBmpMask
*>(pWnd
->GetWindow()) : nullptr;
292 if (bCont
&& pBmpMask
)
294 const Graphic
& rOldGraphic
= xNewObj
->GetGraphic();
295 const Graphic
aNewGraphic(pBmpMask
->Mask(rOldGraphic
));
297 if( aNewGraphic
!= rOldGraphic
)
299 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
301 xNewObj
->SetEmptyPresObj(false);
302 xNewObj
->SetGraphic(pBmpMask
->Mask(xNewObj
->GetGraphic()));
304 OUString aStr
= rMarkList
.GetMarkDescription() +
305 " " + SdResId(STR_EYEDROPPER
);
307 mpDrawView
->BegUndo( aStr
);
308 mpDrawView
->ReplaceObjectAtView(pObj
, *pPV
, xNewObj
.get());
309 mpDrawView
->EndUndo();
321 void DrawViewShell::GetBmpMaskState( SfxItemSet
& rSet
)
323 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
324 const SdrObject
* pObj
= nullptr;
325 bool bEnable
= false;
327 if ( rMarkList
.GetMarkCount() == 1 )
328 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
330 // valid graphic object?
331 if( auto pGrafObj
= dynamic_cast< const SdrGrafObj
*>( pObj
) )
332 if (!pGrafObj
->IsEPS() && !mpDrawView
->IsTextEdit() )
336 rSet
.Put( SfxBoolItem( SID_BMPMASK_EXEC
, bEnable
) );
339 } // end of namespace sd
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */