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 <svx/svdoole2.hxx>
21 #include <svx/svdobj.hxx>
22 #include <svx/graphichelper.hxx>
24 #include <sfx2/objface.hxx>
25 #include <vcl/EnumContext.hxx>
27 #include <chartsh.hxx>
29 #include <viewdata.hxx>
30 #include <drawview.hxx>
31 #include <gridwin.hxx>
32 #include <sfx2/sidebar/SidebarController.hxx>
33 #include <tabvwsh.hxx>
35 #define ShellClass_ScChartShell
36 #include <scslots.hxx>
38 using namespace css::uno
;
39 using namespace sfx2::sidebar
;
41 namespace drawing
= css::drawing
;
45 bool inChartOrMathContext(const ScTabViewShell
* pViewShell
)
47 SidebarController
* pSidebar
= SidebarController::GetSidebarControllerForView(pViewShell
);
49 return pSidebar
->hasChartOrMathContextCurrently();
54 } // anonymous namespace
56 SFX_IMPL_INTERFACE(ScChartShell
, ScDrawShell
)
58 void ScChartShell::InitInterface_Impl()
60 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
,
61 SfxVisibilityFlags::Standard
| SfxVisibilityFlags::Server
,
62 ToolbarId::Draw_Objectbar
);
64 GetStaticInterface()->RegisterPopupMenu(u
"oleobject"_ustr
);
67 void ScChartShell::Activate(bool bMDI
)
69 if(!inChartOrMathContext(GetViewData().GetViewShell()))
70 ScDrawShell::Activate(bMDI
);
73 // Avoid context changes for chart/math during activation / deactivation.
74 const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
76 SfxShell::Activate(bMDI
);
78 SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled
);
82 void ScChartShell::Deactivate(bool bMDI
)
84 if(!inChartOrMathContext(GetViewData().GetViewShell()))
85 ScDrawShell::Deactivate(bMDI
);
88 // Avoid context changes for chart/math during activation / deactivation.
89 const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false));
91 SfxShell::Deactivate(bMDI
);
93 SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled
);
97 ScChartShell::ScChartShell(ScViewData
& rData
) :
100 SetName( u
"ChartObject"_ustr
);
101 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Chart
));
104 ScChartShell::~ScChartShell()
108 void ScChartShell::GetExportAsGraphicState( SfxItemSet
& rSet
)
110 ScDrawView
* pView
= GetViewData().GetScDrawView();
111 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
112 bool bEnable
= false;
113 if( rMarkList
.GetMarkCount() == 1 )
115 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
117 if( dynamic_cast<const SdrOle2Obj
*>( pObj
) )
121 if (GetObjectShell()->isExportLocked())
125 rSet
.DisableItem( SID_EXPORT_AS_GRAPHIC
);
128 void ScChartShell::ExecuteExportAsGraphic( SfxRequest
& )
130 ScDrawView
* pView
= GetViewData().GetScDrawView();
131 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
133 if( rMarkList
.GetMarkCount() == 1 )
135 SdrObject
* pObject
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
137 if( dynamic_cast<const SdrOle2Obj
*>( pObject
) )
139 vcl::Window
* pWin
= GetViewData().GetActiveWin();
140 css::uno::Reference
<css::lang::XComponent
> xComponent
;
141 const SfxObjectShell
* pShell
= GetObjectShell();
144 xComponent
= pShell
->GetModel();
146 Reference
< drawing::XShape
> xSourceDoc( pObject
->getUnoShape() );
147 GraphicHelper::SaveShapeAsGraphic(pWin
? pWin
->GetFrameWeld() : nullptr, xComponent
,
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */