LibreOffice Module sc (master)  1
tabvwsh9.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 <svx/imapdlg.hxx>
21 #include <svx/svdmark.hxx>
22 #include <svx/svdview.hxx>
23 #include <svx/ImageMapInfo.hxx>
24 #include <svx/svxids.hrc>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/sidebar/Sidebar.hxx>
30 #include <svl/whiter.hxx>
31 #include <svl/stritem.hxx>
32 
33 #include "imapwrap.hxx"
34 #include <tabvwsh.hxx>
35 #include <viewdata.hxx>
36 #include <drwlayer.hxx>
37 #include <userdat.hxx>
38 #include <docsh.hxx>
39 
40 #include <svx/galleryitem.hxx>
41 #include <com/sun/star/gallery/GalleryItemType.hpp>
42 
43 class SvxIMapDlg;
44 
46 {
47  sal_uInt16 nSlot = rReq.GetSlot();
48  switch(nSlot)
49  {
50  case SID_GALLERY:
51  {
52  // First make sure that the sidebar is visible
53  GetViewFrame()->ShowChildWindow(SID_SIDEBAR);
54 
56  "GalleryPanel",
57  GetViewFrame()->GetFrame().GetFrameInterface());
58  }
59  break;
60  }
61 }
62 
64 {
65  const SfxItemSet* pArgs = rReq.GetArgs();
66 
67  const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
68  if ( !pGalleryItem )
69  return;
70 
71  sal_Int8 nType( pGalleryItem->GetType() );
72  if ( nType == css::gallery::GalleryItemType::GRAPHIC )
73  {
74  MakeDrawLayer();
75 
76  Graphic aGraphic( pGalleryItem->GetGraphic() );
77  Point aPos = GetInsertPos();
78 
79  PasteGraphic( aPos, aGraphic, OUString() );
80  }
81  else if ( nType == css::gallery::GalleryItemType::MEDIA )
82  {
83  // for sounds (linked or not), insert a hyperlink button,
84  // like in Impress and Writer
85  const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
86  GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_AVMEDIA,
87  SfxCallMode::SYNCHRON, { &aMediaURLItem });
88  }
89 }
90 
92 {
93  sal_uInt16 nSlot = rReq.GetSlot();
94  switch(nSlot)
95  {
96  case SID_IMAP:
97  {
98  SfxViewFrame* pThisFrame = GetViewFrame();
99  sal_uInt16 nId = ScIMapChildWindowId();
100  pThisFrame->ToggleChildWindow( nId );
101  GetViewFrame()->GetBindings().Invalidate( SID_IMAP );
102 
103  if ( pThisFrame->HasChildWindow( nId ) )
104  {
105  SvxIMapDlg* pDlg = GetIMapDlg();
106  if ( pDlg )
107  {
108  SdrView* pDrView = GetScDrawView();
109  if ( pDrView )
110  {
111  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
112  if ( rMarkList.GetMarkCount() == 1 )
113  UpdateIMap( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
114  }
115  }
116  }
117 
118  rReq.Ignore();
119  }
120  break;
121 
122  case SID_IMAP_EXEC:
123  {
124  SdrView* pDrView = GetScDrawView();
125  SdrMark* pMark = pDrView ? pDrView->GetMarkedObjectList().GetMark(0) : nullptr;
126 
127  if ( pMark )
128  {
129  SdrObject* pSdrObj = pMark->GetMarkedSdrObj();
130  SvxIMapDlg* pDlg = GetIMapDlg();
131 
132  if ( ScIMapDlgGetObj(pDlg) == static_cast<void*>(pSdrObj) )
133  {
134  const ImageMap& rImageMap = ScIMapDlgGetMap(pDlg);
135  SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo( pSdrObj );
136 
137  if ( !pIMapInfo )
138  pSdrObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new SvxIMapInfo( rImageMap )) );
139  else
140  pIMapInfo->SetImageMap( rImageMap );
141 
143  }
144  }
145  }
146  break;
147  }
148 }
149 
151 {
152  SfxWhichIter aIter(rSet);
153  sal_uInt16 nWhich = aIter.FirstWhich();
154  while ( nWhich )
155  {
156  switch ( nWhich )
157  {
158  case SID_IMAP:
159  {
160  // We don't disable this anymore
161 
162  bool bThere = false;
163  SfxViewFrame* pThisFrame = GetViewFrame();
164  sal_uInt16 nId = ScIMapChildWindowId();
165  if ( pThisFrame->KnowsChildWindow(nId) )
166  if ( pThisFrame->HasChildWindow(nId) )
167  bThere = true;
168 
170  bool bEnable=(eType==OST_OleObject) ||(eType==OST_Graphic);
171  if(!bThere && !bEnable)
172  {
173  rSet.DisableItem( nWhich );
174  }
175  else
176  {
177  rSet.Put( SfxBoolItem( nWhich, bThere ) );
178  }
179  }
180  break;
181 
182  case SID_IMAP_EXEC:
183  {
184  bool bDisable = true;
185 
186  SdrView* pDrView = GetScDrawView();
187  if ( pDrView )
188  {
189  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
190  if ( rMarkList.GetMarkCount() == 1 )
191  if ( ScIMapDlgGetObj(GetIMapDlg()) ==
192  static_cast<void*>(rMarkList.GetMark(0)->GetMarkedSdrObj()) )
193  bDisable = false;
194  }
195 
196  rSet.Put( SfxBoolItem( SID_IMAP_EXEC, bDisable ) );
197  }
198  break;
199  }
200 
201  nWhich = aIter.NextWhich();
202  }
203 }
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const css::uno::Reference< css::graphic::XGraphic > & GetGraphic() const
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
size_t GetMarkCount() const
void SetImageMap(const ImageMap &rIMap)
SfxViewFrame * GetFrame() const
signed char sal_Int8
SfxDispatcher * GetDispatcher()
bool PasteGraphic(const Point &rPos, const Graphic &rGraphic, const OUString &rFile)
Definition: viewfun7.cxx:377
sal_Int16 nId
sal_uInt16 FirstWhich()
void UpdateIMap(SdrObject *pObj)
Definition: tabview5.cxx:489
SdrMark * GetMark(size_t nNum) const
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
sal_uInt16 NextWhich()
void ToggleChildWindow(sal_uInt16)
SvxIMapDlg * GetIMapDlg()
sal_Int8 GetType() const
ScViewData & GetViewData()
Definition: tabview.hxx:334
DocumentType eType
const ImageMap & ScIMapDlgGetMap(const SvxIMapDlg *pDlg)
Definition: imapwrap.cxx:43
SdrObject * GetMarkedSdrObj() const
SfxBindings & GetBindings()
const SdrMarkList & GetMarkedObjectList() const
void ExecChildWin(const SfxRequest &rReq)
Definition: tabvwsh9.cxx:45
static void ShowPanel(const OUString &rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
const void * ScIMapDlgGetObj(const SvxIMapDlg *pDlg)
Definition: imapwrap.cxx:35
void AppendUserData(std::unique_ptr< SdrObjUserData > pData)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void MakeDrawLayer()
Definition: tabview2.cxx:1393
bool HasChildWindow(sal_uInt16)
const OUString & GetURL() const
void DisableItem(sal_uInt16 nWhich)
ScDrawView * GetScDrawView()
Definition: tabview.hxx:342
bool KnowsChildWindow(sal_uInt16)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
void ShowChildWindow(sal_uInt16, bool bVisible=true)
ObjectSelectionType GetCurObjectSelectionType() const
Definition: tabvwsh.hxx:299
Point GetInsertPos() const
Definition: tabview.cxx:1668
void SetDrawModified()
SetDrawModified - without Formula update.
Definition: docsh.cxx:2883
void ExecImageMap(SfxRequest &rReq)
Definition: tabvwsh9.cxx:91
void ExecGallery(const SfxRequest &rReq)
Definition: tabvwsh9.cxx:63
ObjectSelectionType
Definition: tabvwsh.hxx:75
void Ignore()
void GetImageMapState(SfxItemSet &rSet)
Definition: tabvwsh9.cxx:150
static SvxIMapInfo * GetIMapInfo(const SdrObject *pObject)
sal_uInt16 ScIMapChildWindowId()
Definition: imapwrap.cxx:24