LibreOffice Module chart2 (master) 1
res_LegendPosition.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
21#include <ChartModelHelper.hxx>
22#include <Legend.hxx>
23#include <LegendHelper.hxx>
24#include <ChartModel.hxx>
25#include <Diagram.hxx>
26
27#include <com/sun/star/chart2/LegendPosition.hpp>
28#include <com/sun/star/chart/ChartLegendExpansion.hpp>
29
30//itemset stuff
32#include <svl/intitem.hxx>
33#include <svl/eitem.hxx>
35#include <utility>
36#include <vcl/weld.hxx>
37
38namespace chart
39{
40
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::chart2;
43
45 : m_xRbtLeft(rBuilder.weld_radio_button("left"))
46 , m_xRbtRight(rBuilder.weld_radio_button("right"))
47 , m_xRbtTop(rBuilder.weld_radio_button("top"))
48 , m_xRbtBottom(rBuilder.weld_radio_button("bottom"))
49{
51}
52
55 : m_xCC(std::move(xCC))
56 , m_xCbxShow(rBuilder.weld_check_button("show"))
57 , m_xRbtLeft(rBuilder.weld_radio_button("left"))
58 , m_xRbtRight(rBuilder.weld_radio_button("right"))
59 , m_xRbtTop(rBuilder.weld_radio_button("top"))
60 , m_xRbtBottom(rBuilder.weld_radio_button("bottom"))
61{
62 m_xCbxShow->connect_toggled( LINK( this, LegendPositionResources, PositionEnableHdl ) );
64}
65
67{
68 m_xRbtLeft->connect_toggled( LINK( this, LegendPositionResources, PositionChangeHdl ) );
69 m_xRbtTop->connect_toggled( LINK( this, LegendPositionResources, PositionChangeHdl ) );
70 m_xRbtRight->connect_toggled( LINK( this, LegendPositionResources, PositionChangeHdl ) );
71 m_xRbtBottom->connect_toggled( LINK( this, LegendPositionResources, PositionChangeHdl ) );
72}
73
75{
76}
77
79{
80 try
81 {
82 rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram();
83 rtl::Reference< Legend > xLegend = xDiagram->getLegend2();
84 if( xLegend.is() )
85 {
86 //show
87 bool bShowLegend = false;
88 xLegend->getPropertyValue( "Show" ) >>= bShowLegend;
89 if (m_xCbxShow)
90 m_xCbxShow->set_active( bShowLegend );
92
93 //position
94 chart2::LegendPosition ePos;
95 xLegend->getPropertyValue( "AnchorPosition" ) >>= ePos;
96 switch( ePos )
97 {
98 case chart2::LegendPosition_LINE_START:
99 m_xRbtLeft->set_active(true);
100 break;
101 case chart2::LegendPosition_PAGE_START:
102 m_xRbtTop->set_active(true);
103 break;
104 case chart2::LegendPosition_PAGE_END:
105 m_xRbtBottom->set_active(true);
106 break;
107 case chart2::LegendPosition_LINE_END:
108 default:
109 m_xRbtRight->set_active(true);
110 break;
111 }
112 }
113 }
114 catch( const uno::Exception & )
115 {
116 DBG_UNHANDLED_EXCEPTION("chart2");
117 }
118}
119
121{
122 try
123 {
124 bool bShowLegend = m_xCbxShow && m_xCbxShow->get_active();
125 ChartModel& rModel = *xChartModel;
126 rtl::Reference< Legend > xProp = LegendHelper::getLegend(rModel, m_xCC, bShowLegend);
127 if( xProp.is() )
128 {
129 //show
130 xProp->setPropertyValue( "Show" , uno::Any( bShowLegend ));
131
132 //position
133 chart2::LegendPosition eNewPos;
134 css::chart::ChartLegendExpansion eExp = css::chart::ChartLegendExpansion_HIGH;
135
136 if( m_xRbtLeft->get_active() )
137 eNewPos = chart2::LegendPosition_LINE_START;
138 else if( m_xRbtRight->get_active() )
139 {
140 eNewPos = chart2::LegendPosition_LINE_END;
141 }
142 else if( m_xRbtTop->get_active() )
143 {
144 eNewPos = chart2::LegendPosition_PAGE_START;
145 eExp = css::chart::ChartLegendExpansion_WIDE;
146 }
147 else if( m_xRbtBottom->get_active() )
148 {
149 eNewPos = chart2::LegendPosition_PAGE_END;
150 eExp = css::chart::ChartLegendExpansion_WIDE;
151 }
152
153 xProp->setPropertyValue( "AnchorPosition" , uno::Any( eNewPos ));
154 xProp->setPropertyValue( "Expansion" , uno::Any( eExp ));
155 xProp->setPropertyValue( "RelativePosition" , uno::Any());
156 }
157 }
158 catch( const uno::Exception & )
159 {
160 DBG_UNHANDLED_EXCEPTION("chart2" );
161 }
162}
163
165{
166 PositionEnable();
167}
168
170{
171 bool bEnable = !m_xCbxShow || m_xCbxShow->get_active();
172
173 m_xRbtLeft->set_sensitive( bEnable );
174 m_xRbtTop->set_sensitive( bEnable );
175 m_xRbtRight->set_sensitive( bEnable );
176 m_xRbtBottom->set_sensitive( bEnable );
177
178 m_aChangeLink.Call(nullptr);
179}
180
182{
183 if( const SfxInt32Item* pPosItem = rInAttrs.GetItemIfSet( SCHATTR_LEGEND_POS ) )
184 {
185 chart2::LegendPosition nLegendPosition = static_cast<chart2::LegendPosition>(pPosItem->GetValue());
186 switch( nLegendPosition )
187 {
188 case chart2::LegendPosition_LINE_START:
189 m_xRbtLeft->set_active(true);
190 break;
191 case chart2::LegendPosition_PAGE_START:
192 m_xRbtTop->set_active(true);
193 break;
194 case chart2::LegendPosition_LINE_END:
195 m_xRbtRight->set_active(true);
196 break;
197 case chart2::LegendPosition_PAGE_END:
198 m_xRbtBottom->set_active(true);
199 break;
200 default:
201 break;
202 }
203 }
204
205 const SfxBoolItem* pShowItem;
206 if( m_xCbxShow && (pShowItem = rInAttrs.GetItemIfSet( SCHATTR_LEGEND_SHOW )) )
207 {
208 m_xCbxShow->set_active(pShowItem->GetValue());
209 }
210}
211
213{
214 chart2::LegendPosition nLegendPosition = chart2::LegendPosition_LINE_END;
215 if( m_xRbtLeft->get_active() )
216 nLegendPosition = chart2::LegendPosition_LINE_START;
217 else if( m_xRbtTop->get_active() )
218 nLegendPosition = chart2::LegendPosition_PAGE_START;
219 else if( m_xRbtRight->get_active() )
220 nLegendPosition = chart2::LegendPosition_LINE_END;
221 else if( m_xRbtBottom->get_active() )
222 nLegendPosition = chart2::LegendPosition_PAGE_END;
223 rOutAttrs.Put( SfxInt32Item(SCHATTR_LEGEND_POS, static_cast<sal_Int32>(nLegendPosition) ) );
224
225 rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, !m_xCbxShow || m_xCbxShow->get_active()) );
226}
227
228IMPL_LINK (LegendPositionResources, PositionChangeHdl, weld::Toggleable&, rRadio, void)
229{
230 //for each radio click there are coming two change events
231 //first uncheck of previous button -> ignore that call
232 //the second call gives the check of the new button
233 if( rRadio.get_active() )
234 m_aChangeLink.Call(nullptr);
235}
236
238{
239 m_aChangeLink = rLink;
240}
241
242} //namespace chart
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::chart::ChartAxisLabelPosition ePos
constexpr TypedWhichId< SfxInt32Item > SCHATTR_LEGEND_POS(SCHATTR_LEGEND_START)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_LEGEND_SHOW(SCHATTR_LEGEND_START+1)
bool GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static rtl::Reference< ::chart::Legend > getLegend(ChartModel &rModel, const css::uno::Reference< css::uno::XComponentContext > &xContext=nullptr, bool bCreate=false)
Link< LinkParamNone *, void > m_aChangeLink
void SetChangeHdl(const Link< LinkParamNone *, void > &rLink)
std::unique_ptr< weld::RadioButton > m_xRbtTop
std::unique_ptr< weld::CheckButton > m_xCbxShow
void writeToModel(const rtl::Reference<::chart::ChartModel > &xChartModel) const
std::unique_ptr< weld::RadioButton > m_xRbtLeft
void writeToItemSet(SfxItemSet &rOutAttrs) const
void writeToResources(const rtl::Reference<::chart::ChartModel > &xChartModel)
css::uno::Reference< css::uno::XComponentContext > m_xCC
std::unique_ptr< weld::RadioButton > m_xRbtBottom
LegendPositionResources(weld::Builder &rBuilder)
void initFromItemSet(const SfxItemSet &rInAttrs)
std::unique_ptr< weld::RadioButton > m_xRbtRight
#define DBG_UNHANDLED_EXCEPTION(...)
IMPL_LINK(StackingResourceGroup, StackingChangeHdl, weld::Toggleable &, rRadio, void)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)