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 "DrawViewShell.hxx"
21 #include <vcl/metaact.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <svx/svdograf.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/fontwork.hxx>
29 #include <svx/bmpmask.hxx>
30 #include <svx/imapdlg.hxx>
31 #include <svx/SvxColorChildWindow.hxx>
32 #include <svx/f3dchild.hxx>
33 #include "optsitem.hxx"
34 #include <svx/extrusionbar.hxx>
35 #include <svx/fontworkbar.hxx>
36 #include <svx/tbxcustomshapes.hxx>
37 #include <avmedia/mediaplayer.hxx>
40 #include "strings.hrc"
43 #include "animobjs.hxx"
44 #include "AnimationChildWindow.hxx"
45 #include "NavigatorChildWindow.hxx"
46 #include "sdresid.hxx"
47 #include "drawdoc.hxx"
48 #include "drawview.hxx"
49 #include "FrameView.hxx"
51 #include "DrawDocShell.hxx"
52 #include "sdabstdlg.hxx"
53 #include "framework/FrameworkHelper.hxx"
54 #include <svx/svdoashp.hxx>
55 #include <sfx2/sidebar/Sidebar.hxx>
60 * handle SfxRequests for FontWork
62 void DrawViewShell::ExecFormText(SfxRequest
& rReq
)
64 // nothing is executed during a slide show!
65 if(HasCurrentFunction(SID_PRESENTATION
))
70 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
72 if ( rMarkList
.GetMarkCount() == 1 && rReq
.GetArgs() &&
73 !mpDrawView
->IsPresObjSelected() )
75 const SfxItemSet
& rSet
= *rReq
.GetArgs();
77 if ( mpDrawView
->IsTextEdit() )
78 mpDrawView
->SdrEndTextEdit();
80 mpDrawView
->SetAttributes(rSet
);
85 * Return state values for FontWork
87 void DrawViewShell::GetFormTextState(SfxItemSet
& rSet
)
89 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
90 const SdrObject
* pObj
= NULL
;
91 SvxFontWorkDialog
* pDlg
= NULL
;
93 sal_uInt16 nId
= SvxFontWorkChildWindow::GetChildWindowId();
95 if (GetViewFrame()->HasChildWindow(nId
))
97 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(nId
);
98 pDlg
= pWnd
? static_cast<SvxFontWorkDialog
*>(pWnd
->GetWindow()) : NULL
;
101 if ( rMarkList
.GetMarkCount() == 1 )
102 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
104 const SdrTextObj
* pTextObj
= dynamic_cast< const SdrTextObj
* >(pObj
);
105 const bool bDeactivate(
108 !pTextObj
->HasText() ||
109 dynamic_cast< const SdrObjCustomShape
* >(pObj
)); // #121538# no FontWork for CustomShapes
113 // automatic open/close the FontWork-Dialog; first deactivate it
115 rSet
.DisableItem(XATTR_FORMTXTSTYLE
);
116 rSet
.DisableItem(XATTR_FORMTXTADJUST
);
117 rSet
.DisableItem(XATTR_FORMTXTDISTANCE
);
118 rSet
.DisableItem(XATTR_FORMTXTSTART
);
119 rSet
.DisableItem(XATTR_FORMTXTMIRROR
);
120 rSet
.DisableItem(XATTR_FORMTXTHIDEFORM
);
121 rSet
.DisableItem(XATTR_FORMTXTOUTLINE
);
122 rSet
.DisableItem(XATTR_FORMTXTSHADOW
);
123 rSet
.DisableItem(XATTR_FORMTXTSHDWCOLOR
);
124 rSet
.DisableItem(XATTR_FORMTXTSHDWXVAL
);
125 rSet
.DisableItem(XATTR_FORMTXTSHDWYVAL
);
130 pDlg
->SetColorList(GetDoc()->GetColorList());
132 SfxItemSet
aSet( GetDoc()->GetPool() );
133 mpDrawView
->GetAttributes( aSet
);
138 void DrawViewShell::ExecAnimationWin( SfxRequest
& rReq
)
140 // nothing is executed during a slide show!
141 if (HasCurrentFunction(SID_PRESENTATION
))
146 sal_uInt16 nSId
= rReq
.GetSlot();
150 case SID_ANIMATOR_INIT
:
151 case SID_ANIMATOR_ADD
:
152 case SID_ANIMATOR_CREATE
:
154 AnimationWindow
* pAnimWin
;
155 sal_uInt16 nId
= AnimationChildWindow::GetChildWindowId();
157 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(nId
);
159 pAnimWin
= pWnd
? static_cast<AnimationWindow
*>(pWnd
->GetWindow()) : NULL
;
163 if( nSId
== SID_ANIMATOR_ADD
)
164 pAnimWin
->AddObj( *mpDrawView
);
165 else if( nSId
== SID_ANIMATOR_CREATE
)
166 pAnimWin
->CreateAnimObj( *mpDrawView
);
177 * Return status values for animator
179 * nValue == 0 -> No button
180 * nValue == 1 -> Button 'accept'
181 * nValue == 2 -> Button 'accept individually'
182 * nValue == 3 -> Buttons 'accept' and 'accept individually'
184 void DrawViewShell::GetAnimationWinState( SfxItemSet
& rSet
)
186 // here we could disable buttons etc.
189 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
190 const size_t nMarkCount
= rMarkList
.GetMarkCount();
192 if( nMarkCount
== 0 )
194 else if( nMarkCount
> 1 )
198 const SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
199 sal_uInt32 nInv
= pObj
->GetObjInventor();
200 sal_uInt16 nId
= pObj
->GetObjIdentifier();
201 // 1 selected group object
202 if( nInv
== SdrInventor
&& nId
== OBJ_GRUP
)
204 else if( nInv
== SdrInventor
&& nId
== OBJ_GRAF
) // Animated GIF ?
206 sal_uInt16 nCount
= 0;
208 if( static_cast<const SdrGrafObj
*>(pObj
)->IsAnimated() )
209 nCount
= static_cast<const SdrGrafObj
*>(pObj
)->GetGraphic().GetAnimation().Count();
218 rSet
.Put( SfxUInt16Item( SID_ANIMATOR_STATE
, nValue
) );
221 void DrawViewShell::SetChildWindowState( SfxItemSet
& rSet
)
223 // State of SfxChild-Windows (Animator, Fontwork etc.)
224 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_FONTWORK
) )
226 sal_uInt16 nId
= SvxFontWorkChildWindow::GetChildWindowId();
227 rSet
.Put(SfxBoolItem(SID_FONTWORK
, GetViewFrame()->HasChildWindow(nId
)));
229 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_COLOR_CONTROL
) )
231 sal_uInt16 nId
= SvxColorChildWindow::GetChildWindowId();
232 rSet
.Put(SfxBoolItem(SID_COLOR_CONTROL
, GetViewFrame()->HasChildWindow(nId
)));
234 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_ANIMATION_OBJECTS
) )
236 sal_uInt16 nId
= AnimationChildWindow::GetChildWindowId();
237 rSet
.Put( SfxBoolItem( SID_ANIMATION_OBJECTS
, GetViewFrame()->HasChildWindow( nId
) ) );
239 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_NAVIGATOR
) )
241 sal_uInt16 nId
= SID_NAVIGATOR
;
242 rSet
.Put( SfxBoolItem( SID_NAVIGATOR
, GetViewFrame()->HasChildWindow( nId
) ) );
244 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_BMPMASK
) )
246 sal_uInt16 nId
= SvxBmpMaskChildWindow::GetChildWindowId();
247 rSet
.Put( SfxBoolItem( SID_BMPMASK
, GetViewFrame()->HasChildWindow( nId
) ) );
249 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_IMAP
) )
251 sal_uInt16 nId
= SvxIMapDlgChildWindow::GetChildWindowId();
252 rSet
.Put( SfxBoolItem( SID_IMAP
, GetViewFrame()->HasChildWindow( nId
) ) );
254 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_3D_WIN
) )
256 sal_uInt16 nId
= Svx3DChildWindow::GetChildWindowId();
257 rSet
.Put( SfxBoolItem( SID_3D_WIN
, GetViewFrame()->HasChildWindow( nId
) ) );
259 if( SfxItemState::DEFAULT
== rSet
.GetItemState( SID_AVMEDIA_PLAYER
) )
261 sal_uInt16 nId
= ::avmedia::MediaPlayer::GetChildWindowId();
262 rSet
.Put( SfxBoolItem( SID_AVMEDIA_PLAYER
, GetViewFrame()->HasChildWindow( nId
) ) );
267 * Handle SfxRequests for pipette
269 void DrawViewShell::ExecBmpMask( SfxRequest
& rReq
)
271 // nothing is executed during a slide show!
272 if (HasCurrentFunction(SID_PRESENTATION
))
275 switch ( rReq
.GetSlot() )
277 case ( SID_BMPMASK_PIPETTE
) :
279 mbPipette
= static_cast<const SfxBoolItem
&>( rReq
.GetArgs()->
280 Get( SID_BMPMASK_PIPETTE
) ).GetValue();
284 case ( SID_BMPMASK_EXEC
) :
286 SdrGrafObj
* pObj
= 0;
287 if( mpDrawView
&& mpDrawView
->GetMarkedObjectList().GetMarkCount() )
288 pObj
= dynamic_cast< SdrGrafObj
* >( mpDrawView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj() );
290 if ( pObj
&& !mpDrawView
->IsTextEdit() )
292 SdrGrafObj
* pNewObj
= pObj
->Clone();
295 if( pNewObj
->IsLinkedGraphic() )
297 ScopedVclPtrInstance
< MessageDialog
> aQueryBox( (vcl::Window
*) GetActiveWindow(),"QueryUnlinkImageDialog","modules/sdraw/ui/queryunlinkimagedialog.ui");
299 if (RET_YES
== aQueryBox
->Execute())
300 pNewObj
->ReleaseGraphicLink();
308 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(
309 SvxBmpMaskChildWindow::GetChildWindowId());
310 SvxBmpMask
* pBmpMask
= pWnd
? static_cast<SvxBmpMask
*>(pWnd
->GetWindow()) : NULL
;
312 if (bCont
&& pBmpMask
)
314 const Graphic
& rOldGraphic
= pNewObj
->GetGraphic();
315 const Graphic
aNewGraphic(pBmpMask
->Mask(rOldGraphic
));
317 if( aNewGraphic
!= rOldGraphic
)
319 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
321 pNewObj
->SetEmptyPresObj( false );
322 pNewObj
->SetGraphic(pBmpMask
->Mask(pNewObj
->GetGraphic()));
324 OUString
aStr( mpDrawView
->GetDescriptionOfMarkedObjects() );
325 aStr
+= " " + SD_RESSTR(STR_EYEDROPPER
);
327 mpDrawView
->BegUndo( aStr
);
328 mpDrawView
->ReplaceObjectAtView( pObj
, *pPV
, pNewObj
);
329 mpDrawView
->EndUndo();
341 void DrawViewShell::GetBmpMaskState( SfxItemSet
& rSet
)
343 const SdrMarkList
& rMarkList
= mpDrawView
->GetMarkedObjectList();
344 const SdrObject
* pObj
= NULL
;
345 sal_uInt16 nId
= SvxBmpMaskChildWindow::GetChildWindowId();
346 bool bEnable
= false;
348 if ( GetViewFrame()->HasChildWindow( nId
) )
350 SfxChildWindow
* pWnd
= GetViewFrame()->GetChildWindow(nId
);
351 SvxBmpMask
* pDlg
= pWnd
? static_cast<SvxBmpMask
*>(pWnd
->GetWindow()) : NULL
;
352 if (pDlg
&& pDlg
->NeedsColorList())
353 pDlg
->SetColorList(GetDoc()->GetColorList());
356 if ( rMarkList
.GetMarkCount() == 1 )
357 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
359 // valid graphic object?
360 if( pObj
&& pObj
->ISA( SdrGrafObj
) &&
361 !static_cast<const SdrGrafObj
*>(pObj
)->IsEPS() &&
362 !mpDrawView
->IsTextEdit() )
368 rSet
.Put( SfxBoolItem( SID_BMPMASK_EXEC
, bEnable
) );
371 } // end of namespace sd
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */