LibreOffice Module sw (master)  1
mediash.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 
20 #include <cmdid.h>
21 #include <svl/whiter.hxx>
22 #include <sfx2/request.hxx>
23 #include <svx/svdview.hxx>
24 #include <view.hxx>
25 #include <wrtsh.hxx>
26 #include <mediash.hxx>
27 
28 #include <sfx2/objface.hxx>
29 #include <vcl/EnumContext.hxx>
30 #include <svx/svdomedia.hxx>
32 #include <avmedia/mediaitem.hxx>
33 
34 #define ShellClass_SwMediaShell
35 #include <sfx2/msg.hxx>
36 #include <swslots.hxx>
37 #include <memory>
38 
40 
42 {
44 
45  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Media_Toolbox);
46 }
47 
49 {
50  SwWrtShell* pSh = &GetShell();
51  SdrView* pSdrView = pSh->GetDrawView();
52 
53  if( !pSdrView )
54  return;
55 
56  const SfxItemSet* pArgs = rReq.GetArgs();
57  bool bChanged = pSdrView->GetModel()->IsChanged();
58 
59  pSdrView->GetModel()->SetChanged( false );
60 
61  switch( rReq.GetSlot() )
62  {
63  case SID_DELETE:
64  {
65  if( pSh->IsObjSelected() )
66  {
67  pSh->SetModified();
68  pSh->DelSelectedObj();
69 
70  if( pSh->IsSelFrameMode() )
71  pSh->LeaveSelFrameMode();
72 
73  GetView().AttrChangedNotify(nullptr);
74  }
75  }
76  break;
77 
78  case SID_AVMEDIA_TOOLBOX:
79  {
80  if( pSh->IsObjSelected() )
81  {
82  const SfxPoolItem* pItem;
83 
84  if( !pArgs || ( SfxItemState::SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, false, &pItem ) ) )
85  pItem = nullptr;
86 
87  if( pItem )
88  {
89  std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pSdrView->GetMarkedObjectList() ));
90 
91  if( 1 == pMarkList->GetMarkCount() )
92  {
93  SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
94 
95  if( dynamic_cast< const SdrMediaObj *>( pObj ) )
96  {
97  static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
98  static_cast< const ::avmedia::MediaItem& >( *pItem ) );
99  }
100  }
101  }
102  }
103  }
104  break;
105 
106  default:
107  break;
108  }
109 
110  if( pSdrView->GetModel()->IsChanged() )
111  GetShell().SetModified();
112  else if( bChanged )
113  pSdrView->GetModel()->SetChanged();
114 }
115 
117 {
118  SfxWhichIter aIter( rSet );
119  sal_uInt16 nWhich = aIter.FirstWhich();
120 
121  while( nWhich )
122  {
123  if( SID_AVMEDIA_TOOLBOX == nWhich )
124  {
125  SwWrtShell& rSh = GetShell();
126  SdrView* pView = rSh.GetDrawView();
127 
128  if( pView )
129  {
130  bool bDisable = true;
131  std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
132 
133  if( 1 == pMarkList->GetMarkCount() )
134  {
135  SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
136 
137  if( dynamic_cast< const SdrMediaObj *>( pObj ) )
138  {
139  ::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
140 
141  static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
142  rSet.Put( aItem );
143  bDisable = false;
144  }
145  }
146 
147  if( bDisable )
148  rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
149  }
150  }
151 
152  nWhich = aIter.NextWhich();
153  }
154 }
155 
157  SwBaseShell(_rView)
158 
159 {
160  SetName("Media Playback");
162 }
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwView & GetView()
Definition: basesh.hxx:57
#define SFX_IMPL_INTERFACE(Class, SuperClass)
SdrView * GetDrawView()
Definition: vnew.cxx:375
static SfxInterface * GetStaticInterface()
void GetMediaState(SfxItemSet &)
Definition: mediash.cxx:116
SwWrtShell & GetShell()
Definition: basesh.cxx:2687
void RegisterObjectBar(sal_uInt16, SfxVisibilityFlags nFlags, ToolbarId eId)
SwMediaShell(SwView &rView)
Definition: mediash.cxx:156
static void InitInterface_Impl()
but we implement this ourselves.
Definition: docsh.cxx:114
void ExecMedia(SfxRequest const &)
Definition: mediash.cxx:48
sal_uInt16 FirstWhich()
void SetModified()
Definition: edws.cxx:70
const SfxItemSet * GetArgs() const
void RegisterPopupMenu(const OUString &)
sdr::contact::ViewContact & GetViewContact() const
sal_uInt16 NextWhich()
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
virtual void SetChanged(bool bFlg=true)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SdrMarkList & GetMarkedObjectList() const
void SetName(const OUString &rName)
#define SFX_OBJECTBAR_OBJECT
bool IsChanged() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
static const OUString & GetContextName(const Context eContext)
void DisableItem(sal_uInt16 nWhich)
size_t IsObjSelected() const
Definition: feshview.cxx:1149
void DelSelectedObj()
Definition: feshview.cxx:2280
void LeaveSelFrameMode()
Definition: select.cxx:719
SdrModel * GetModel() const
void SetContextName(const OUString &rsContextName)
Definition: view.hxx:144
bool IsSelFrameMode() const
Definition: wrtsh.hxx:170