1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: res_LegendPosition.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "res_LegendPosition.hxx"
35 #include "ResourceIds.hrc"
36 #include "Strings.hrc"
37 #include "res_LegendPosition_IDs.hrc"
39 #include "ChartModelHelper.hxx"
41 #include "LegendHelper.hxx"
43 #ifndef _SVT_CONTROLDIMS_HRC_
44 #include <svtools/controldims.hrc>
46 #include <com/sun/star/chart2/LegendPosition.hpp>
47 #include <com/sun/star/chart2/LegendExpansion.hpp>
50 #include "chartview/ChartSfxItemIds.hxx"
51 #include <svx/chrtitem.hxx>
52 // header for class SfxItemPool
53 #include <svtools/itempool.hxx>
55 //.............................................................................
58 //.............................................................................
60 using namespace ::com::sun::star
;
61 using namespace ::com::sun::star::chart2
;
63 LegendPositionResources::LegendPositionResources( Window
* pWindow
)
64 : m_xCC() //unused in this scenario
65 , m_aCbxShow( pWindow
) //unused in this scenario
66 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
67 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
68 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
69 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
71 m_aCbxShow
.Check();//legend is assumed to be visible in this scenario
72 impl_setRadioButtonToggleHdl();
75 LegendPositionResources::LegendPositionResources( Window
* pWindow
, const uno::Reference
< uno::XComponentContext
>& xCC
)
77 , m_aCbxShow( pWindow
, SchResId(CBX_SHOWLEGEND
) )
78 , m_aRbtLeft( pWindow
, SchResId(RBT_LEFT
) )
79 , m_aRbtTop( pWindow
, SchResId(RBT_TOP
) )
80 , m_aRbtRight( pWindow
, SchResId(RBT_RIGHT
) )
81 , m_aRbtBottom( pWindow
, SchResId(RBT_BOTTOM
) )
83 m_aCbxShow
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionEnableHdl
) );
84 impl_setRadioButtonToggleHdl();
87 void LegendPositionResources::impl_setRadioButtonToggleHdl()
89 m_aRbtLeft
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
90 m_aRbtTop
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
91 m_aRbtRight
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
92 m_aRbtBottom
.SetToggleHdl( LINK( this, LegendPositionResources
, PositionChangeHdl
) );
95 LegendPositionResources::~LegendPositionResources()
99 void LegendPositionResources::writeToResources( const uno::Reference
< frame::XModel
>& xChartModel
)
103 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram( xChartModel
);
104 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
->getLegend(), uno::UNO_QUERY
);
108 sal_Bool bShowLegend
= sal_False
;
109 xProp
->getPropertyValue( C2U("Show") ) >>= bShowLegend
;
110 m_aCbxShow
.Check( bShowLegend
);
111 PositionEnableHdl(0);
114 chart2::LegendPosition ePos
;
115 xProp
->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos
;
118 case chart2::LegendPosition_LINE_START
:
121 case chart2::LegendPosition_LINE_END
:
124 case chart2::LegendPosition_PAGE_START
:
127 case chart2::LegendPosition_PAGE_END
:
128 m_aRbtBottom
.Check();
131 case chart2::LegendPosition_CUSTOM
:
138 catch( uno::Exception
& ex
)
140 ASSERT_EXCEPTION( ex
);
144 void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference
< frame::XModel
>& xChartModel
) const
148 sal_Bool bShowLegend
= static_cast<sal_Bool
>(m_aCbxShow
.IsChecked());
149 uno::Reference
< beans::XPropertySet
> xProp( LegendHelper::getLegend( xChartModel
,m_xCC
,bShowLegend
), uno::UNO_QUERY
);
153 xProp
->setPropertyValue( C2U("Show"), uno::makeAny( bShowLegend
));
156 chart2::LegendPosition eNewPos
;
157 chart2::LegendExpansion eExp
= chart2::LegendExpansion_HIGH
;
159 if( m_aRbtLeft
.IsChecked() )
160 eNewPos
= chart2::LegendPosition_LINE_START
;
161 else if( m_aRbtRight
.IsChecked() )
163 eNewPos
= chart2::LegendPosition_LINE_END
;
165 else if( m_aRbtTop
.IsChecked() )
167 eNewPos
= chart2::LegendPosition_PAGE_START
;
168 eExp
= chart2::LegendExpansion_WIDE
;
170 else if( m_aRbtBottom
.IsChecked() )
172 eNewPos
= chart2::LegendPosition_PAGE_END
;
173 eExp
= chart2::LegendExpansion_WIDE
;
176 xProp
->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos
));
177 xProp
->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp
));
178 xProp
->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
181 catch( uno::Exception
& ex
)
183 ASSERT_EXCEPTION( ex
);
187 IMPL_LINK( LegendPositionResources
, PositionEnableHdl
, void*, EMPTYARG
)
189 BOOL bEnable
= m_aCbxShow
.IsChecked();
191 m_aRbtLeft
.Enable( bEnable
);
192 m_aRbtTop
.Enable( bEnable
);
193 m_aRbtRight
.Enable( bEnable
);
194 m_aRbtBottom
.Enable( bEnable
);
196 m_aChangeLink
.Call(NULL
);
201 void LegendPositionResources::initFromItemSet( const SfxItemSet
& rInAttrs
)
203 SvxChartLegendPos ePos
= CHLEGEND_NONE
;
205 const SfxPoolItem
* pPoolItem
= NULL
;
206 if( rInAttrs
.GetItemState( SCHATTR_LEGEND_POS
,
207 TRUE
, &pPoolItem
) != SFX_ITEM_SET
)
208 pPoolItem
= &(rInAttrs
.GetPool()->GetDefaultItem( SCHATTR_LEGEND_POS
));
211 ePos
= ((const SvxChartLegendPosItem
*)pPoolItem
)->GetValue();
216 m_aRbtLeft
.Check(TRUE
);
219 m_aRbtTop
.Check(TRUE
);
222 m_aRbtRight
.Check(TRUE
);
224 case CHLEGEND_BOTTOM
:
225 m_aRbtBottom
.Check(TRUE
);
232 void LegendPositionResources::writeToItemSet( SfxItemSet
& rOutAttrs
) const
234 SvxChartLegendPos ePos
;
236 if( m_aRbtLeft
.IsChecked() )
237 ePos
= CHLEGEND_LEFT
;
238 else if( m_aRbtTop
.IsChecked() )
240 else if( m_aRbtRight
.IsChecked() )
241 ePos
= CHLEGEND_RIGHT
;
242 else if( m_aRbtBottom
.IsChecked() )
243 ePos
= CHLEGEND_BOTTOM
;
245 ePos
= CHLEGEND_NONE
;
247 rOutAttrs
.Put(SvxChartLegendPosItem( ePos
, SCHATTR_LEGEND_POS
));
250 IMPL_LINK( LegendPositionResources
, PositionChangeHdl
, RadioButton
*, pRadio
)
252 //for each radio click ther are coming two change events
253 //first uncheck of previous button -> ignore that call
254 //the second call gives the check of the new button
255 if( pRadio
&& pRadio
->IsChecked() )
256 m_aChangeLink
.Call(NULL
);
260 void LegendPositionResources::SetChangeHdl( const Link
& rLink
)
262 m_aChangeLink
= rLink
;
265 //.............................................................................
267 //.............................................................................