1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "res_LegendPosition.hxx"
32 #include "ResourceIds.hrc"
33 #include "Strings.hrc"
34 #include "res_LegendPosition_IDs.hrc"
36 #include "ChartModelHelper.hxx"
38 #include "LegendHelper.hxx"
40 #ifndef _SVT_CONTROLDIMS_HRC_
41 #include <svtools/controldims.hrc>
43 #include <com/sun/star/chart2/LegendPosition.hpp>
44 #include <com/sun/star/chart2/LegendExpansion.hpp>
47 #include "chartview/ChartSfxItemIds.hxx"
48 #include <svx/chrtitem.hxx>
49 // header for class SfxItemPool
50 #include <svl/itempool.hxx>
52 //.............................................................................
55 //.............................................................................
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::chart2
;
60 LegendPositionResources::LegendPositionResources( Window
* pWindow
)
61 : m_xCC() //unused in this scenario
62 , m_aCbxShow( pWindow
) //unused in this scenario
63 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
64 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
65 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
66 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
68 m_aCbxShow
.Check();//legend is assumed to be visible in this scenario
69 impl_setRadioButtonToggleHdl();
72 LegendPositionResources::LegendPositionResources( Window
* pWindow
, const uno::Reference
< uno::XComponentContext
>& xCC
)
74 , m_aCbxShow( pWindow
, SchResId(CBX_SHOWLEGEND
) )
75 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
76 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
77 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
78 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
80 m_aCbxShow
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionEnableHdl
) );
81 impl_setRadioButtonToggleHdl();
84 void LegendPositionResources::impl_setRadioButtonToggleHdl()
86 m_aRbtLeft
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
87 m_aRbtTop
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
88 m_aRbtRight
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
89 m_aRbtBottom
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
92 LegendPositionResources::~LegendPositionResources()
96 void LegendPositionResources::writeToResources( const uno::Reference
< frame::XModel
>& xChartModel
)
100 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram( xChartModel
);
101 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
->getLegend(), uno::UNO_QUERY
);
105 sal_Bool bShowLegend
= sal_False
;
106 xProp
->getPropertyValue( C2U("Show") ) >>= bShowLegend
;
107 m_aCbxShow
.Check( bShowLegend
);
108 PositionEnableHdl(0);
111 chart2::LegendPosition ePos
;
112 xProp
->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos
;
115 case chart2::LegendPosition_LINE_START
:
118 case chart2::LegendPosition_LINE_END
:
121 case chart2::LegendPosition_PAGE_START
:
124 case chart2::LegendPosition_PAGE_END
:
125 m_aRbtBottom
.Check();
128 case chart2::LegendPosition_CUSTOM
:
135 catch( uno::Exception
& ex
)
137 ASSERT_EXCEPTION( ex
);
141 void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference
< frame::XModel
>& xChartModel
) const
145 sal_Bool bShowLegend
= static_cast<sal_Bool
>(m_aCbxShow
.IsChecked());
146 uno::Reference
< beans::XPropertySet
> xProp( LegendHelper::getLegend( xChartModel
,m_xCC
,bShowLegend
), uno::UNO_QUERY
);
150 xProp
->setPropertyValue( C2U("Show"), uno::makeAny( bShowLegend
));
153 chart2::LegendPosition eNewPos
;
154 chart2::LegendExpansion eExp
= chart2::LegendExpansion_HIGH
;
156 if( m_aRbtLeft
.IsChecked() )
157 eNewPos
= chart2::LegendPosition_LINE_START
;
158 else if( m_aRbtRight
.IsChecked() )
160 eNewPos
= chart2::LegendPosition_LINE_END
;
162 else if( m_aRbtTop
.IsChecked() )
164 eNewPos
= chart2::LegendPosition_PAGE_START
;
165 eExp
= chart2::LegendExpansion_WIDE
;
167 else if( m_aRbtBottom
.IsChecked() )
169 eNewPos
= chart2::LegendPosition_PAGE_END
;
170 eExp
= chart2::LegendExpansion_WIDE
;
173 xProp
->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos
));
174 xProp
->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp
));
175 xProp
->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
178 catch( uno::Exception
& ex
)
180 ASSERT_EXCEPTION( ex
);
184 IMPL_LINK( LegendPositionResources
, PositionEnableHdl
, void*, EMPTYARG
)
186 BOOL bEnable
= m_aCbxShow
.IsChecked();
188 m_aRbtLeft
.Enable( bEnable
);
189 m_aRbtTop
.Enable( bEnable
);
190 m_aRbtRight
.Enable( bEnable
);
191 m_aRbtBottom
.Enable( bEnable
);
193 m_aChangeLink
.Call(NULL
);
198 void LegendPositionResources::initFromItemSet( const SfxItemSet
& rInAttrs
)
200 SvxChartLegendPos ePos
= CHLEGEND_NONE
;
202 const SfxPoolItem
* pPoolItem
= NULL
;
203 if( rInAttrs
.GetItemState( SCHATTR_LEGEND_POS
,
204 TRUE
, &pPoolItem
) != SFX_ITEM_SET
)
205 pPoolItem
= &(rInAttrs
.GetPool()->GetDefaultItem( SCHATTR_LEGEND_POS
));
208 ePos
= ((const SvxChartLegendPosItem
*)pPoolItem
)->GetValue();
213 m_aRbtLeft
.Check(TRUE
);
216 m_aRbtTop
.Check(TRUE
);
219 m_aRbtRight
.Check(TRUE
);
221 case CHLEGEND_BOTTOM
:
222 m_aRbtBottom
.Check(TRUE
);
229 void LegendPositionResources::writeToItemSet( SfxItemSet
& rOutAttrs
) const
231 SvxChartLegendPos ePos
;
233 if( m_aRbtLeft
.IsChecked() )
234 ePos
= CHLEGEND_LEFT
;
235 else if( m_aRbtTop
.IsChecked() )
237 else if( m_aRbtRight
.IsChecked() )
238 ePos
= CHLEGEND_RIGHT
;
239 else if( m_aRbtBottom
.IsChecked() )
240 ePos
= CHLEGEND_BOTTOM
;
242 ePos
= CHLEGEND_NONE
;
244 rOutAttrs
.Put(SvxChartLegendPosItem( ePos
, SCHATTR_LEGEND_POS
));
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 //.............................................................................
264 //.............................................................................