LibreOffice Module sc (master)  1
chartsh.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/svdoole2.hxx>
21 #include <svx/svdobj.hxx>
22 #include <svx/graphichelper.hxx>
23 
24 #include <sfx2/objface.hxx>
25 #include <vcl/EnumContext.hxx>
26 
27 #include <chartsh.hxx>
28 #include <sc.hrc>
29 #include <viewdata.hxx>
30 #include <drawview.hxx>
31 #include <gridwin.hxx>
33 #include <tabvwsh.hxx>
34 
35 #define ShellClass_ScChartShell
36 #include <scslots.hxx>
37 
38 using namespace css::uno;
39 using namespace sfx2::sidebar;
40 
42 
43 namespace {
44 
45 bool inChartContext(ScTabViewShell* pViewShell)
46 {
47  SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell);
48  if (pSidebar)
49  return pSidebar->hasChartContextCurrently();
50 
51  return false;
52 }
53 
54 } // anonymous namespace
55 
57 
58 void ScChartShell::InitInterface_Impl()
59 {
60  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT,
61  SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server,
62  ToolbarId::Draw_Objectbar);
63 
64  GetStaticInterface()->RegisterPopupMenu("oleobject");
65 }
66 
67 void ScChartShell::Activate(bool bMDI)
68 {
69  if(!inChartContext(GetViewData().GetViewShell()))
71  else
72  {
73  // Avoid context changes for chart during activation / deactivation.
74  const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
75 
76  SfxShell::Activate(bMDI);
77 
78  SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled);
79  }
80 }
81 
82 void ScChartShell::Deactivate(bool bMDI)
83 {
84  if(!inChartContext(GetViewData().GetViewShell()))
86  else
87  {
88  // Avoid context changes for chart during activation / deactivation.
89  const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
90 
92 
93  SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled);
94  }
95 }
96 
98  ScDrawShell(rData)
99 {
100  SetName( "ChartObject" );
102 }
103 
105 {
106 }
107 
109 {
110  ScDrawView* pView = GetViewData().GetScDrawView();
111  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
112  bool bEnable = false;
113  if( rMarkList.GetMarkCount() == 1 )
114  {
115  SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
116 
117  if( dynamic_cast<const SdrOle2Obj*>( pObj) )
118  bEnable = true;
119  }
120 
121  if (GetObjectShell()->isExportLocked())
122  bEnable = false;
123 
124  if( !bEnable )
125  rSet.DisableItem( SID_EXPORT_AS_GRAPHIC );
126 }
127 
129 {
130  ScDrawView* pView = GetViewData().GetScDrawView();
131  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
132 
133  if( rMarkList.GetMarkCount() == 1 )
134  {
135  SdrObject* pObject = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
136 
137  if( dynamic_cast<const SdrOle2Obj*>( pObject) )
138  {
140  Reference< drawing::XShape > xSourceDoc( pObject->getUnoShape(), UNO_QUERY_THROW );
141  GraphicHelper::SaveShapeAsGraphic(pWin ? pWin->GetFrameWeld() : nullptr, xSourceDoc);
142  }
143  }
144 
145  Invalidate();
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetMarkCount() const
#define SFX_IMPL_INTERFACE(Class, SuperClass)
ScViewData & GetViewData()
Definition: drawsh.hxx:50
void GetExportAsGraphicState(SfxItemSet &rSet)
Definition: chartsh.cxx:108
virtual void Deactivate(bool bMDI) override
Definition: chartsh.cxx:82
virtual void Activate(bool bMDI) override
Definition: chartsh.cxx:67
SdrMark * GetMark(size_t nNum) const
EmbeddedObjectRef * pObject
weld::Window * GetFrameWeld() const
virtual css::uno::Reference< css::uno::XInterface > getUnoShape()
virtual void Deactivate(bool bMDI)
virtual void Activate(bool bMDI) override
Definition: drawsh2.cxx:540
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3127
bool SetContextBroadcasterEnabled(const bool bIsEnabled)
SdrObject * GetMarkedSdrObj() const
const SdrMarkList & GetMarkedObjectList() const
void ExecuteExportAsGraphic(SfxRequest &rReq)
Definition: chartsh.cxx:128
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3115
void SetName(const OUString &rName)
#define SFX_OBJECTBAR_OBJECT
static void SaveShapeAsGraphic(weld::Window *pWin, const css::uno::Reference< css::drawing::XShape > &xShape)
static const OUString & GetContextName(const Context eContext)
void DisableItem(sal_uInt16 nWhich)
virtual ~ScChartShell() override
Definition: chartsh.cxx:104
ScChartShell(ScViewData &rData)
Definition: chartsh.cxx:97
virtual void Invalidate(sal_uInt16 nId=0)
virtual void Activate(bool bMDI)
void SetContextName(const OUString &rsContextName)
virtual SfxObjectShell * GetObjectShell()
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo