Debian Codegraph @

chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx

raw
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 <LegendItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <GraphicPropertyItemConverter.hxx>
23 #include <CharacterPropertyItemConverter.hxx>
24 #include <ChartModel.hxx>
25 #include <com/sun/star/chart2/LegendPosition.hpp>
26 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28
29 #include <svl/intitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <comphelper/diagnose_ex.hxx>
32
33 #include <memory>
34
35 using namespace ::com::sun::star;
36
37 namespace chart::wrapper
38 {
39
40 LegendItemConverter::LegendItemConverter(
41 const css::uno::Reference< css::beans::XPropertySet > & rPropertySet,
42 SfxItemPool& rItemPool,
43 SdrModel& rDrawModel,
44 const rtl::Reference< ChartModel > & xChartModel,
45 const std::optional<awt::Size>& pRefSize ) :
46 ItemConverter( rPropertySet, rItemPool )
47 {
48 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
49 rPropertySet, rItemPool, rDrawModel, xChartModel,
50 GraphicObjectType::LineAndFillProperties ));
51 m_aConverters.emplace_back( new CharacterPropertyItemConverter(
52 rPropertySet, rItemPool, pRefSize,
53 u"ReferencePageSize"_ustr ));
54 }
55
56 LegendItemConverter::~LegendItemConverter()
57 {
58 }
59
60 void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
61 {
62 for( const auto& pConv : m_aConverters )
63 pConv->FillItemSet( rOutItemSet );
64
65 // own items
66 ItemConverter::FillItemSet( rOutItemSet );
67 }
68
69 bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
70 {
71 bool bResult = false;
72
73 for( const auto& pConv : m_aConverters )
74 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
75
76 // own items
77 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
78 }
79
80 const WhichRangesContainer& LegendItemConverter::GetWhichPairs() const
81 {
82 // must span all used items!
83 return nLegendWhichPairs;
84 }
85
86 bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
87 {
88 // No own (non-special) properties
89 return false;
90 }
91
92 bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
93 {
94 bool bChanged = false;
95
96 switch( nWhichId )
97 {
98 case SCHATTR_LEGEND_SHOW:
99 {
100 if( const SfxBoolItem* pShowItem = rInItemSet.GetItemIfSet( SCHATTR_LEGEND_SHOW ) )
101 {
102 bool bShow = pShowItem->GetValue();
103 bool bWasShown = true;
104 if( ! (GetPropertySet()->getPropertyValue( u"Show"_ustr ) >>= bWasShown) ||
105 ( bWasShown != bShow ))
106 {
107 GetPropertySet()->setPropertyValue( u"Show"_ustr , uno::Any( bShow ));
108 bChanged = true;
109 }
110 }
111
112 }
113 break;
114 case SCHATTR_LEGEND_POS:
115 {
116 if( const SfxInt32Item* pPosItem = rInItemSet.GetItemIfSet( SCHATTR_LEGEND_POS ) )
117 {
118 chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(pPosItem->GetValue());
119
120 css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH;
121 switch( eNewPos )
122 {
123 case chart2::LegendPosition_LINE_START:
124 case chart2::LegendPosition_LINE_END:
125 eExpansion = css::chart::ChartLegendExpansion_HIGH;
126 break;
127 case chart2::LegendPosition_PAGE_START:
128 case chart2::LegendPosition_PAGE_END:
129 eExpansion = css::chart::ChartLegendExpansion_WIDE;
130 break;
131 default:
132 break;
133 }
134
135 try
136 {
137 chart2::LegendPosition eOldPos;
138 if( ! ( GetPropertySet()->getPropertyValue( u"AnchorPosition"_ustr ) >>= eOldPos ) ||
139 ( eOldPos != eNewPos ))
140 {
141 GetPropertySet()->setPropertyValue( u"AnchorPosition"_ustr , uno::Any( eNewPos ));
142 GetPropertySet()->setPropertyValue( u"Expansion"_ustr , uno::Any( eExpansion ));
143 GetPropertySet()->setPropertyValue( u"RelativePosition"_ustr , uno::Any());
144 bChanged = true;
145 }
146 }
147 catch( const uno::Exception & )
148 {
149 DBG_UNHANDLED_EXCEPTION("chart2");
150 }
151 }
152 }
153 break;
154 case SCHATTR_LEGEND_NO_OVERLAY:
155 {
156 if(const SfxBoolItem* pNoOverlayItem = rInItemSet.GetItemIfSet(SCHATTR_LEGEND_NO_OVERLAY))
157 {
158 bool bOverlay = !pNoOverlayItem->GetValue();
159 bool bOldOverlay = false;
160 if(!(GetPropertySet()->getPropertyValue(u"Overlay"_ustr) >>= bOldOverlay) ||
161 (bOldOverlay != bOverlay))
162 {
163 GetPropertySet()->setPropertyValue(u"Overlay"_ustr, uno::Any(bOverlay));
164 bChanged = true;
165 }
166 }
167
168 }
169 break;
170 }
171
172 return bChanged;
173 }
174
175 void LegendItemConverter::FillSpecialItem(
176 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
177 {
178 switch( nWhichId )
179 {
180 case SCHATTR_LEGEND_SHOW:
181 {
182 bool bShow = true;
183 GetPropertySet()->getPropertyValue( u"Show"_ustr ) >>= bShow;
184 rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
185 }
186 break;
187 case SCHATTR_LEGEND_POS:
188 {
189 chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
190 GetPropertySet()->getPropertyValue( u"AnchorPosition"_ustr ) >>= eLegendPos;
191 rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, static_cast<sal_Int32>(eLegendPos) ) );
192 }
193 break;
194 case SCHATTR_LEGEND_NO_OVERLAY:
195 {
196 bool bOverlay = false;
197 GetPropertySet()->getPropertyValue(u"Overlay"_ustr) >>= bOverlay;
198 rOutItemSet.Put(SfxBoolItem(SCHATTR_LEGEND_NO_OVERLAY, !bOverlay));
199 }
200 break;
201 }
202 }
203
204 } // namespace chart::wrapper
205
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */