fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / res_LegendPosition.cxx
blobce21c1c31c8874a325a91916a91b5a572714b552
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "res_LegendPosition.hxx"
21 #include "ChartModelHelper.hxx"
22 #include "macros.hxx"
23 #include "LegendHelper.hxx"
24 #include "ChartModel.hxx"
26 #include <svtools/controldims.hrc>
27 #include <com/sun/star/chart2/LegendPosition.hpp>
28 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
30 //itemset stuff
31 #include "chartview/ChartSfxItemIds.hxx"
32 #include <svl/intitem.hxx>
33 #include <svl/eitem.hxx>
35 namespace chart
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::chart2;
41 LegendPositionResources::LegendPositionResources(VclBuilderContainer& rParent)
42 : m_xCC() //unused in this scenario
43 , m_pCbxShow( NULL ) //unused in this scenario, assumed to be visible
45 rParent.get(m_pRbtLeft, "left");
46 rParent.get(m_pRbtRight, "right");
47 rParent.get(m_pRbtTop, "top");
48 rParent.get(m_pRbtBottom, "bottom");
49 impl_setRadioButtonToggleHdl();
52 LegendPositionResources::LegendPositionResources(VclBuilderContainer& rParent,
53 const uno::Reference< uno::XComponentContext >& xCC)
54 : m_xCC(xCC)
56 rParent.get(m_pCbxShow, "show");
57 rParent.get(m_pRbtLeft, "left");
58 rParent.get(m_pRbtRight, "right");
59 rParent.get(m_pRbtTop, "top");
60 rParent.get(m_pRbtBottom, "bottom");
62 m_pCbxShow->SetToggleHdl( LINK( this, LegendPositionResources, PositionEnableHdl ) );
63 impl_setRadioButtonToggleHdl();
66 void LegendPositionResources::impl_setRadioButtonToggleHdl()
68 m_pRbtLeft->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
69 m_pRbtTop->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
70 m_pRbtRight->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
71 m_pRbtBottom->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
74 LegendPositionResources::~LegendPositionResources()
78 void LegendPositionResources::writeToResources( const uno::Reference< frame::XModel >& xChartModel )
80 try
82 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartModel );
83 uno::Reference< beans::XPropertySet > xProp( xDiagram->getLegend(), uno::UNO_QUERY );
84 if( xProp.is() )
86 //show
87 bool bShowLegend = false;
88 xProp->getPropertyValue( "Show" ) >>= bShowLegend;
89 if (m_pCbxShow)
90 m_pCbxShow->Check( bShowLegend );
91 PositionEnableHdl(0);
93 //position
94 chart2::LegendPosition ePos;
95 xProp->getPropertyValue( "AnchorPosition" ) >>= ePos;
96 switch( ePos )
98 case chart2::LegendPosition_LINE_START:
99 m_pRbtLeft->Check();
100 break;
101 case chart2::LegendPosition_LINE_END:
102 m_pRbtRight->Check();
103 break;
104 case chart2::LegendPosition_PAGE_START:
105 m_pRbtTop->Check();
106 break;
107 case chart2::LegendPosition_PAGE_END:
108 m_pRbtBottom->Check();
109 break;
111 case chart2::LegendPosition_CUSTOM:
112 default:
113 m_pRbtRight->Check();
114 break;
118 catch( const uno::Exception & ex )
120 ASSERT_EXCEPTION( ex );
124 void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference< frame::XModel >& xChartModel ) const
128 bool bShowLegend = m_pCbxShow && m_pCbxShow->IsChecked();
129 ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel.get());
130 uno::Reference< beans::XPropertySet > xProp(LegendHelper::getLegend(rModel, m_xCC, bShowLegend), uno::UNO_QUERY);
131 if( xProp.is() )
133 //show
134 xProp->setPropertyValue( "Show" , uno::makeAny( bShowLegend ));
136 //position
137 chart2::LegendPosition eNewPos;
138 ::com::sun::star::chart::ChartLegendExpansion eExp = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
140 if( m_pRbtLeft->IsChecked() )
141 eNewPos = chart2::LegendPosition_LINE_START;
142 else if( m_pRbtRight->IsChecked() )
144 eNewPos = chart2::LegendPosition_LINE_END;
146 else if( m_pRbtTop->IsChecked() )
148 eNewPos = chart2::LegendPosition_PAGE_START;
149 eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
151 else if( m_pRbtBottom->IsChecked() )
153 eNewPos = chart2::LegendPosition_PAGE_END;
154 eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
157 xProp->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos ));
158 xProp->setPropertyValue( "Expansion" , uno::makeAny( eExp ));
159 xProp->setPropertyValue( "RelativePosition" , uno::Any());
162 catch( const uno::Exception & ex )
164 ASSERT_EXCEPTION( ex );
168 IMPL_LINK_NOARG(LegendPositionResources, PositionEnableHdl)
170 bool bEnable = m_pCbxShow == nullptr || m_pCbxShow->IsChecked();
172 m_pRbtLeft->Enable( bEnable );
173 m_pRbtTop->Enable( bEnable );
174 m_pRbtRight->Enable( bEnable );
175 m_pRbtBottom->Enable( bEnable );
177 m_aChangeLink.Call(NULL);
179 return 0;
182 void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
184 const SfxPoolItem* pPoolItem = NULL;
185 if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET )
187 sal_Int32 nLegendPosition = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
188 switch( nLegendPosition )
190 case chart2::LegendPosition_LINE_START:
191 m_pRbtLeft->Check(true);
192 break;
193 case chart2::LegendPosition_PAGE_START:
194 m_pRbtTop->Check(true);
195 break;
196 case chart2::LegendPosition_LINE_END:
197 m_pRbtRight->Check(true);
198 break;
199 case chart2::LegendPosition_PAGE_END:
200 m_pRbtBottom->Check(true);
201 break;
202 default:
203 break;
207 if( m_pCbxShow && rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET )
209 bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
210 m_pCbxShow->Check(bShow);
214 void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const
216 sal_Int32 nLegendPosition = chart2::LegendPosition_CUSTOM;
217 if( m_pRbtLeft->IsChecked() )
218 nLegendPosition = chart2::LegendPosition_LINE_START;
219 else if( m_pRbtTop->IsChecked() )
220 nLegendPosition = chart2::LegendPosition_PAGE_START;
221 else if( m_pRbtRight->IsChecked() )
222 nLegendPosition = chart2::LegendPosition_LINE_END;
223 else if( m_pRbtBottom->IsChecked() )
224 nLegendPosition = chart2::LegendPosition_PAGE_END;
225 rOutAttrs.Put(SfxInt32Item(SCHATTR_LEGEND_POS, nLegendPosition ));
227 rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, m_pCbxShow == nullptr || m_pCbxShow->IsChecked()) );
230 IMPL_LINK( LegendPositionResources, PositionChangeHdl, RadioButton*, pRadio )
232 //for each radio click there are coming two change events
233 //first uncheck of previous button -> ignore that call
234 //the second call gives the check of the new button
235 if( pRadio && pRadio->IsChecked() )
236 m_aChangeLink.Call(NULL);
237 return 0;
240 void LegendPositionResources::SetChangeHdl( const Link<>& rLink )
242 m_aChangeLink = rLink;
245 } //namespace chart
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */