1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "res_LegendPosition.hxx"
31 #include "ResourceIds.hrc"
32 #include "Strings.hrc"
33 #include "res_LegendPosition_IDs.hrc"
35 #include "ChartModelHelper.hxx"
37 #include "LegendHelper.hxx"
39 #include <svtools/controldims.hrc>
40 #include <com/sun/star/chart2/LegendPosition.hpp>
41 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
44 #include "chartview/ChartSfxItemIds.hxx"
45 #include <svl/intitem.hxx>
46 #include <svl/eitem.hxx>
48 //.............................................................................
51 //.............................................................................
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::chart2
;
56 LegendPositionResources::LegendPositionResources( Window
* pWindow
)
57 : m_xCC() //unused in this scenario
58 , m_aCbxShow( pWindow
) //unused in this scenario
59 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
60 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
61 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
62 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
64 m_aCbxShow
.Check();//legend is assumed to be visible in this scenario
65 impl_setRadioButtonToggleHdl();
68 LegendPositionResources::LegendPositionResources( Window
* pWindow
, const uno::Reference
< uno::XComponentContext
>& xCC
)
70 , m_aCbxShow( pWindow
, SchResId(CBX_SHOWLEGEND
) )
71 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
72 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
73 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
74 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
76 m_aCbxShow
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionEnableHdl
) );
77 impl_setRadioButtonToggleHdl();
78 m_aCbxShow
.SetAccessibleRelationMemberOf(&m_aCbxShow
);
79 m_aRbtLeft
.SetAccessibleRelationMemberOf(&m_aCbxShow
);
80 m_aRbtRight
.SetAccessibleRelationMemberOf(&m_aCbxShow
);
81 m_aRbtTop
.SetAccessibleRelationMemberOf(&m_aCbxShow
);
82 m_aRbtBottom
.SetAccessibleRelationMemberOf(&m_aCbxShow
);
85 void LegendPositionResources::impl_setRadioButtonToggleHdl()
87 m_aRbtLeft
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
88 m_aRbtTop
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
89 m_aRbtRight
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
90 m_aRbtBottom
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
93 LegendPositionResources::~LegendPositionResources()
97 void LegendPositionResources::writeToResources( const uno::Reference
< frame::XModel
>& xChartModel
)
101 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram( xChartModel
);
102 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
->getLegend(), uno::UNO_QUERY
);
106 sal_Bool bShowLegend
= sal_False
;
107 xProp
->getPropertyValue( C2U("Show") ) >>= bShowLegend
;
108 m_aCbxShow
.Check( bShowLegend
);
109 PositionEnableHdl(0);
112 chart2::LegendPosition ePos
;
113 xProp
->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos
;
116 case chart2::LegendPosition_LINE_START
:
119 case chart2::LegendPosition_LINE_END
:
122 case chart2::LegendPosition_PAGE_START
:
125 case chart2::LegendPosition_PAGE_END
:
126 m_aRbtBottom
.Check();
129 case chart2::LegendPosition_CUSTOM
:
136 catch( const uno::Exception
& ex
)
138 ASSERT_EXCEPTION( ex
);
142 void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference
< frame::XModel
>& xChartModel
) const
146 sal_Bool bShowLegend
= static_cast<sal_Bool
>(m_aCbxShow
.IsChecked());
147 uno::Reference
< beans::XPropertySet
> xProp( LegendHelper::getLegend( xChartModel
,m_xCC
,bShowLegend
), uno::UNO_QUERY
);
151 xProp
->setPropertyValue( C2U("Show"), uno::makeAny( bShowLegend
));
154 chart2::LegendPosition eNewPos
;
155 ::com::sun::star::chart::ChartLegendExpansion eExp
= ::com::sun::star::chart::ChartLegendExpansion_HIGH
;
157 if( m_aRbtLeft
.IsChecked() )
158 eNewPos
= chart2::LegendPosition_LINE_START
;
159 else if( m_aRbtRight
.IsChecked() )
161 eNewPos
= chart2::LegendPosition_LINE_END
;
163 else if( m_aRbtTop
.IsChecked() )
165 eNewPos
= chart2::LegendPosition_PAGE_START
;
166 eExp
= ::com::sun::star::chart::ChartLegendExpansion_WIDE
;
168 else if( m_aRbtBottom
.IsChecked() )
170 eNewPos
= chart2::LegendPosition_PAGE_END
;
171 eExp
= ::com::sun::star::chart::ChartLegendExpansion_WIDE
;
174 xProp
->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos
));
175 xProp
->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp
));
176 xProp
->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
179 catch( const uno::Exception
& ex
)
181 ASSERT_EXCEPTION( ex
);
185 IMPL_LINK_NOARG(LegendPositionResources
, PositionEnableHdl
)
187 sal_Bool bEnable
= m_aCbxShow
.IsChecked();
189 m_aRbtLeft
.Enable( bEnable
);
190 m_aRbtTop
.Enable( bEnable
);
191 m_aRbtRight
.Enable( bEnable
);
192 m_aRbtBottom
.Enable( bEnable
);
194 m_aChangeLink
.Call(NULL
);
199 void LegendPositionResources::initFromItemSet( const SfxItemSet
& rInAttrs
)
201 const SfxPoolItem
* pPoolItem
= NULL
;
202 if( rInAttrs
.GetItemState( SCHATTR_LEGEND_POS
, sal_True
, &pPoolItem
) == SFX_ITEM_SET
)
204 sal_Int32 nLegendPosition
= ((const SfxInt32Item
*)pPoolItem
)->GetValue();
205 switch( nLegendPosition
)
207 case chart2::LegendPosition_LINE_START
:
208 m_aRbtLeft
.Check(sal_True
);
210 case chart2::LegendPosition_PAGE_START
:
211 m_aRbtTop
.Check(sal_True
);
213 case chart2::LegendPosition_LINE_END
:
214 m_aRbtRight
.Check(sal_True
);
216 case chart2::LegendPosition_PAGE_END
:
217 m_aRbtBottom
.Check(sal_True
);
224 if( rInAttrs
.GetItemState( SCHATTR_LEGEND_SHOW
, sal_True
, &pPoolItem
) == SFX_ITEM_SET
)
226 bool bShow
= static_cast< const SfxBoolItem
* >( pPoolItem
)->GetValue();
227 m_aCbxShow
.Check(bShow
);
231 void LegendPositionResources::writeToItemSet( SfxItemSet
& rOutAttrs
) const
233 sal_Int32 nLegendPosition
= chart2::LegendPosition_CUSTOM
;
234 if( m_aRbtLeft
.IsChecked() )
235 nLegendPosition
= chart2::LegendPosition_LINE_START
;
236 else if( m_aRbtTop
.IsChecked() )
237 nLegendPosition
= chart2::LegendPosition_PAGE_START
;
238 else if( m_aRbtRight
.IsChecked() )
239 nLegendPosition
= chart2::LegendPosition_LINE_END
;
240 else if( m_aRbtBottom
.IsChecked() )
241 nLegendPosition
= chart2::LegendPosition_PAGE_END
;
242 rOutAttrs
.Put(SfxInt32Item(SCHATTR_LEGEND_POS
, nLegendPosition
));
244 rOutAttrs
.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW
, m_aCbxShow
.IsChecked()) );
247 IMPL_LINK( LegendPositionResources
, PositionChangeHdl
, RadioButton
*, pRadio
)
249 //for each radio click ther are coming two change events
250 //first uncheck of previous button -> ignore that call
251 //the second call gives the check of the new button
252 if( pRadio
&& pRadio
->IsChecked() )
253 m_aChangeLink
.Call(NULL
);
257 void LegendPositionResources::SetChangeHdl( const Link
& rLink
)
259 m_aChangeLink
= rLink
;
262 void LegendPositionResources::SetAccessibleRelationMemberOf(Window
* pMemberOf
)
264 m_aRbtLeft
.SetAccessibleRelationMemberOf(pMemberOf
);
265 m_aRbtRight
.SetAccessibleRelationMemberOf(pMemberOf
);
266 m_aRbtTop
.SetAccessibleRelationMemberOf(pMemberOf
);
267 m_aRbtBottom
.SetAccessibleRelationMemberOf(pMemberOf
);
270 //.............................................................................
272 //.............................................................................
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */