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