/src/libreoffice/sc/source/ui/drawfunc/chartsh.cxx
Line | Count | Source |
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> |
32 | | #include <sfx2/sidebar/SidebarController.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 | | |
41 | | namespace drawing = css::drawing; |
42 | | |
43 | | namespace { |
44 | | |
45 | | bool inChartOrMathContext(const ScTabViewShell* pViewShell) |
46 | 0 | { |
47 | 0 | SidebarController* pSidebar = SidebarController::GetSidebarControllerForView(pViewShell); |
48 | 0 | if (pSidebar) |
49 | 0 | return pSidebar->hasChartOrMathContextCurrently(); |
50 | | |
51 | 0 | return false; |
52 | 0 | } |
53 | | |
54 | | } // anonymous namespace |
55 | | |
56 | | SFX_IMPL_INTERFACE(ScChartShell, ScDrawShell) |
57 | | |
58 | | void ScChartShell::InitInterface_Impl() |
59 | 11 | { |
60 | 11 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, |
61 | 11 | SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server, |
62 | 11 | ToolbarId::Draw_Objectbar); |
63 | | |
64 | 11 | GetStaticInterface()->RegisterPopupMenu(u"oleobject"_ustr); |
65 | 11 | } |
66 | | |
67 | | void ScChartShell::Activate(bool bMDI) |
68 | 0 | { |
69 | 0 | if(!inChartOrMathContext(GetViewData().GetViewShell())) |
70 | 0 | ScDrawShell::Activate(bMDI); |
71 | 0 | else |
72 | 0 | { |
73 | | // Avoid context changes for chart/math during activation / deactivation. |
74 | 0 | const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); |
75 | |
|
76 | 0 | SfxShell::Activate(bMDI); |
77 | |
|
78 | 0 | SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | void ScChartShell::Deactivate(bool bMDI) |
83 | 0 | { |
84 | 0 | if(!inChartOrMathContext(GetViewData().GetViewShell())) |
85 | 0 | ScDrawShell::Deactivate(bMDI); |
86 | 0 | else |
87 | 0 | { |
88 | | // Avoid context changes for chart/math during activation / deactivation. |
89 | 0 | const bool bIsContextBroadcasterEnabled (SfxShell::SetContextBroadcasterEnabled(false)); |
90 | |
|
91 | 0 | SfxShell::Deactivate(bMDI); |
92 | |
|
93 | 0 | SfxShell::SetContextBroadcasterEnabled(bIsContextBroadcasterEnabled); |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | | ScChartShell::ScChartShell(ScViewData& rData) : |
98 | 0 | ScDrawShell(rData) |
99 | 0 | { |
100 | 0 | SetName( u"ChartObject"_ustr ); |
101 | 0 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Chart)); |
102 | 0 | } |
103 | | |
104 | | ScChartShell::~ScChartShell() |
105 | 0 | { |
106 | 0 | } |
107 | | |
108 | | void ScChartShell::GetExportAsGraphicState( SfxItemSet& rSet ) |
109 | 0 | { |
110 | 0 | ScDrawView* pView = GetViewData().GetScDrawView(); |
111 | 0 | const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); |
112 | 0 | bool bEnable = false; |
113 | 0 | if( rMarkList.GetMarkCount() == 1 ) |
114 | 0 | { |
115 | 0 | SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj(); |
116 | |
|
117 | 0 | if( dynamic_cast<const SdrOle2Obj*>( pObj) ) |
118 | 0 | bEnable = true; |
119 | 0 | } |
120 | |
|
121 | 0 | if (GetObjectShell()->isExportLocked()) |
122 | 0 | bEnable = false; |
123 | |
|
124 | 0 | if( !bEnable ) |
125 | 0 | rSet.DisableItem( SID_EXPORT_AS_GRAPHIC ); |
126 | 0 | } |
127 | | |
128 | | void ScChartShell::ExecuteExportAsGraphic( SfxRequest& ) |
129 | 0 | { |
130 | 0 | ScDrawView* pView = GetViewData().GetScDrawView(); |
131 | 0 | const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); |
132 | |
|
133 | 0 | if( rMarkList.GetMarkCount() == 1 ) |
134 | 0 | { |
135 | 0 | SdrObject* pObject = rMarkList.GetMark( 0 )->GetMarkedSdrObj(); |
136 | |
|
137 | 0 | if( dynamic_cast<const SdrOle2Obj*>( pObject) ) |
138 | 0 | { |
139 | 0 | vcl::Window* pWin = GetViewData().GetActiveWin(); |
140 | 0 | css::uno::Reference<css::lang::XComponent> xComponent; |
141 | 0 | const SfxObjectShell* pShell = GetObjectShell(); |
142 | 0 | if (pShell) |
143 | 0 | { |
144 | 0 | xComponent = pShell->GetModel(); |
145 | 0 | } |
146 | 0 | Reference< drawing::XShape > xSourceDoc( pObject->getUnoShape() ); |
147 | 0 | GraphicHelper::SaveShapeAsGraphic(pWin ? pWin->GetFrameWeld() : nullptr, xComponent, |
148 | 0 | xSourceDoc); |
149 | 0 | } |
150 | 0 | } |
151 | |
|
152 | 0 | Invalidate(); |
153 | 0 | } |
154 | | |
155 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |