LibreOffice Module oox (master)  1
ShapeFilterBase.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 
24 #include <oox/ole/vbaproject.hxx>
25 #include <oox/drawingml/theme.hxx>
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
30 
31 namespace oox::shape {
32 
33 using namespace ::com::sun::star;
34 
35 ShapeFilterBase::ShapeFilterBase( const uno::Reference< uno::XComponentContext >& rxContext ) :
36  XmlFilterBase( rxContext ),
37  mxChartConv( std::make_shared<::oox::drawingml::chart::ChartConverter>() )
38 {
39 }
40 
42 {
43 }
44 
45 const ::oox::drawingml::Theme* ShapeFilterBase::getCurrentTheme() const
46 {
47  return mpTheme.get();
48 }
49 
51 {
52  mpTheme = pTheme;
53 }
54 
56 {
57  return nullptr;
58 }
59 
61 {
63 }
64 
66 {
67  return mxChartConv.get();
68 }
69 
71 {
72  return new ::oox::ole::VbaProject( getComponentContext(), getModel(), u"Writer" );
73 }
74 
76 {
77  return OUString();
78 }
79 
80 namespace {
81 
83 class ShapeGraphicHelper : public GraphicHelper
84 {
85 public:
86  explicit ShapeGraphicHelper( const ShapeFilterBase& rFilter );
87  virtual ::Color getSchemeColor( sal_Int32 nToken ) const override;
88 private:
89  const ShapeFilterBase& mrFilter;
90 };
91 
92 }
93 
94 ShapeGraphicHelper::ShapeGraphicHelper( const ShapeFilterBase& rFilter ) :
95  GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
96  mrFilter( rFilter )
97 {
98 }
99 
100 ::Color ShapeGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
101 {
102  return mrFilter.getSchemeColor( nToken );
103 }
104 
105 GraphicHelper* ShapeFilterBase::implCreateGraphicHelper() const
106 {
107  GraphicHelper* pGraphicHelper = new ShapeGraphicHelper(*this);
108  if (mxGraphicMapper.is())
109  pGraphicHelper->setGraphicMapper(mxGraphicMapper);
110  return pGraphicHelper;
111 }
112 
113 ::Color ShapeFilterBase::getSchemeColor( sal_Int32 nToken ) const
114 {
115  ::Color nColor;
116 
117  if (mpTheme)
118  mpTheme->getClrScheme().getColor( nToken, nColor );
119 
120  return nColor;
121 }
122 
123 void ShapeFilterBase::importTheme()
124 {
125  drawingml::ThemePtr pTheme = std::make_shared<drawingml::Theme>();
126  uno::Reference<beans::XPropertySet> xPropSet(getModel(), uno::UNO_QUERY_THROW);
127  uno::Sequence<beans::PropertyValue> aGrabBag;
128  xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
129 
130  for (const auto& rProp : std::as_const(aGrabBag))
131  {
132  if (rProp.Name == "OOXTheme")
133  {
134  uno::Reference<xml::sax::XFastSAXSerializable> xDoc;
135  if (rProp.Value >>= xDoc)
136  {
137  rtl::Reference<core::FragmentHandler> xFragmentHandler(
138  new drawingml::ThemeFragmentHandler(*this, OUString(), *pTheme));
139  importFragment(xFragmentHandler, xDoc);
140  setCurrentTheme(pTheme);
141  }
142  }
143  }
144 }
145 
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
virtual ::oox::drawingml::table::TableStyleListPtr getTableStyles() override
Has to be implemented by each filter to return TableStyles.
const ShapeFilterBase & mrFilter
std::shared_ptr< TableStyleList > TableStyleListPtr
void setCurrentTheme(const ::oox::drawingml::ThemePtr &pTheme)
virtual ::oox::vml::Drawing * getVmlDrawing() override
Has to be implemented by each filter to return the collection of VML shapes.
std::shared_ptr< T > make_shared(Args &&...args)
static void importFragment(core::XmlFilterBase &rFilter, const uno::Reference< xml::dom::XDocument > &rXDom, const OUString &rDocName, const DiagramPtr &pDiagram, const rtl::Reference< core::FragmentHandler > &rxHandler)
Definition: diagram.cxx:186
std::shared_ptr< ::oox::drawingml::chart::ChartConverter > mxChartConv
ShapeFilterBase(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual ~ShapeFilterBase() override
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:531
void setGraphicMapper(css::uno::Reference< css::graphic::XGraphicMapper > const &rxGraphicMapper)
float u
::oox::drawingml::ThemePtr mpTheme
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Returns the component context passed in the filter constructor (always existing). ...
Definition: filterbase.cxx:215
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
Definition: filterbase.cxx:220
virtual const ::oox::drawingml::Theme * getCurrentTheme() const override
Has to be implemented by each filter, returns the current theme.
virtual ::oox::drawingml::chart::ChartConverter * getChartConverter() override
Has to be implemented by each filter, returns a filter-specific chart converter object, that should be global per imported document.
Represents the collection of VML shapes for a complete draw page.
Definition: vmldrawing.hxx:93
virtual OUString SAL_CALL getImplementationName() override
virtual ::oox::ole::VbaProject * implCreateVbaProject() const override
Derived classes create a VBA project manager object.
std::shared_ptr< Theme > ThemePtr