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
38using namespace css::uno;
39using namespace sfx2::sidebar;
40
42
43namespace {
44
45bool inChartOrMathContext(const ScTabViewShell* pViewShell)
46{
47 SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell);
48 if (pSidebar)
49 return pSidebar->hasChartOrMathContextCurrently();
50
51 return false;
52}
53
54} // anonymous namespace
55
57
58void 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
68{
69 if(!inChartOrMathContext(GetViewData().GetViewShell()))
71 else
72 {
73 // Avoid context changes for chart/math during activation / deactivation.
74 const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
75
77
78 SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled);
79 }
80}
81
83{
84 if(!inChartOrMathContext(GetViewData().GetViewShell()))
86 else
87 {
88 // Avoid context changes for chart/math 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{
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{
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 css::uno::Reference<css::lang::XComponent> xComponent;
141 const SfxObjectShell* pShell = GetObjectShell();
142 if (pShell)
143 {
144 xComponent = pShell->GetModel();
145 }
146 Reference< drawing::XShape > xSourceDoc( pObject->getUnoShape() );
147 GraphicHelper::SaveShapeAsGraphic(pWin ? pWin->GetFrameWeld() : nullptr, xComponent,
148 xSourceDoc);
149 }
150 }
151
152 Invalidate();
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void SaveShapeAsGraphic(weld::Window *pWin, const css::uno::Reference< css::lang::XComponent > &xComponent, const css::uno::Reference< css::drawing::XShape > &xShape)
virtual void Deactivate(bool bMDI) override
Definition: chartsh.cxx:82
virtual void Activate(bool bMDI) override
Definition: chartsh.cxx:67
void ExecuteExportAsGraphic(SfxRequest &rReq)
Definition: chartsh.cxx:128
void GetExportAsGraphicState(SfxItemSet &rSet)
Definition: chartsh.cxx:108
virtual ~ScChartShell() override
Definition: chartsh.cxx:104
ScChartShell(ScViewData &rData)
Definition: chartsh.cxx:97
virtual void Activate(bool bMDI) override
Definition: drawsh2.cxx:549
ScViewData & GetViewData()
Definition: drawsh.hxx:48
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3162
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3174
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
void DisableItem(sal_uInt16 nWhich)
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual void Activate(bool bMDI)
bool SetContextBroadcasterEnabled(const bool bIsEnabled)
void SetContextName(const OUString &rsContextName)
virtual void Invalidate(sal_uInt16 nId=0)
virtual void Deactivate(bool bMDI)
virtual SfxObjectShell * GetObjectShell()
SfxViewShell * GetViewShell() const
void SetName(const OUString &rName)
bool hasChartOrMathContextCurrently() const
static const OUString & GetContextName(const Context eContext)
weld::Window * GetFrameWeld() const
EmbeddedObjectRef * pObject
#define SFX_OBJECTBAR_OBJECT
static SfxItemSet & rSet
#define SFX_IMPL_INTERFACE(Class, SuperClass)