1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "tp_AxisLabel.hxx"
31 
32 #include "ResId.hxx"
33 #include "TabPages.hrc"
34 #include "chartview/ChartSfxItemIds.hxx"
35 #include "NoWarningThisInCTOR.hxx"
36 
37 // header for SvxChartTextOrientItem / SvxChartTextOrderItem
38 #include <svx/chrtitem.hxx>
39 
40 // header for SfxInt32Item
41 #include <svl/intitem.hxx>
42 #include <editeng/eeitem.hxx>
43 #include <editeng/frmdiritem.hxx>
44 
45 //.............................................................................
46 namespace chart
47 {
48 //.............................................................................
49 
50 SchAxisLabelTabPage::SchAxisLabelTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
51 		SfxTabPage( pParent, SchResId( TP_AXIS_LABEL ), rInAttrs ),
52 
53 		aCbShowDescription( this, SchResId( CB_AXIS_LABEL_SCHOW_DESCR ) ),
54 
55 		aFlOrder( this, SchResId( FL_AXIS_LABEL_ORDER ) ),
56 		aRbSideBySide( this, SchResId( RB_AXIS_LABEL_SIDEBYSIDE ) ),
57 		aRbUpDown( this, SchResId( RB_AXIS_LABEL_UPDOWN ) ),
58 		aRbDownUp( this, SchResId( RB_AXIS_LABEL_DOWNUP ) ),
59 		aRbAuto( this, SchResId( RB_AXIS_LABEL_AUTOORDER ) ),
60 
61         aFlSeparator( this, SchResId( FL_SEPARATOR ) ),
62         aFlTextFlow( this, SchResId( FL_AXIS_LABEL_TEXTFLOW ) ),
63         aCbTextOverlap( this, SchResId( CB_AXIS_LABEL_TEXTOVERLAP ) ),
64         aCbTextBreak( this, SchResId( CB_AXIS_LABEL_TEXTBREAK ) ),
65 
66         aFlOrient( this, SchResId( FL_AXIS_LABEL_ORIENTATION ) ),
67         aCtrlDial( this, SchResId( CT_AXIS_LABEL_DIAL ) ),
68         aFtRotate( this, SchResId( FT_AXIS_LABEL_DEGREES ) ),
69         aNfRotate( this, SchResId( NF_AXIS_LABEL_ORIENT ) ),
70         aCbStacked( this, SchResId( PB_AXIS_LABEL_TEXTSTACKED ) ),
71         aOrientHlp( aCtrlDial, aNfRotate, aCbStacked ),
72 
73         m_aFtTextDirection( this, SchResId( FT_AXIS_TEXTDIR ) ),
74         m_aLbTextDirection( this, SchResId( LB_AXIS_TEXTDIR ), &m_aFtTextDirection ),
75 
76 		m_bShowStaggeringControls( true ),
77 
78         m_nInitialDegrees( 0 ),
79         m_bHasInitialDegrees( true ),
80         m_bInitialStacking( false ),
81         m_bHasInitialStacking( true ),
82         m_bComplexCategories( false )
83 {
84 	FreeResource();
85 
86     aCbStacked.EnableTriState( sal_False );
87     aOrientHlp.AddDependentWindow( aFlOrient );
88     aOrientHlp.AddDependentWindow( aFtRotate, STATE_CHECK );
89 
90 	aCbShowDescription.SetClickHdl( LINK( this, SchAxisLabelTabPage, ToggleShowLabel ) );
91 
92     //	Make the fixed line separator vertical.
93     aFlSeparator.SetStyle (aFlSeparator.GetStyle() | WB_VERT);
94 
95 	Construct();
96 }
97 
98 SchAxisLabelTabPage::~SchAxisLabelTabPage()
99 {}
100 
101 void SchAxisLabelTabPage::Construct()
102 {
103 }
104 
105 
106 SfxTabPage* SchAxisLabelTabPage::Create( Window* pParent, const SfxItemSet& rAttrs )
107 {
108 	return new SchAxisLabelTabPage( pParent, rAttrs );
109 }
110 
111 sal_Bool SchAxisLabelTabPage::FillItemSet( SfxItemSet& rOutAttrs )
112 {
113     bool bStacked = false;
114     if( aOrientHlp.GetStackedState() != STATE_DONTKNOW )
115     {
116         bStacked = aOrientHlp.GetStackedState() == STATE_CHECK;
117         if( !m_bHasInitialStacking || (bStacked != m_bInitialStacking) )
118             rOutAttrs.Put( SfxBoolItem( SCHATTR_TEXT_STACKED, bStacked ) );
119     }
120 
121     if( aCtrlDial.HasRotation() )
122     {
123         sal_Int32 nDegrees = bStacked ? 0 : aCtrlDial.GetRotation();
124         if( !m_bHasInitialDegrees || (nDegrees != m_nInitialDegrees) )
125             rOutAttrs.Put( SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
126     }
127 
128     if( m_bShowStaggeringControls )
129 	{
130 		SvxChartTextOrder eOrder = CHTXTORDER_SIDEBYSIDE;
131         bool bRadioButtonChecked = true;
132 
133 		if( aRbUpDown.IsChecked())
134 			eOrder = CHTXTORDER_UPDOWN;
135 		else if( aRbDownUp.IsChecked())
136 			eOrder = CHTXTORDER_DOWNUP;
137 		else if( aRbAuto.IsChecked())
138 			eOrder = CHTXTORDER_AUTO;
139 		else if( aRbSideBySide.IsChecked())
140             eOrder = CHTXTORDER_SIDEBYSIDE;
141         else
142             bRadioButtonChecked = false;
143 
144         if( bRadioButtonChecked )
145             rOutAttrs.Put( SvxChartTextOrderItem( eOrder, SCHATTR_AXIS_LABEL_ORDER ));
146 	}
147 
148     if( aCbTextOverlap.GetState() != STATE_DONTKNOW )
149         rOutAttrs.Put( SfxBoolItem( SCHATTR_AXIS_LABEL_OVERLAP, aCbTextOverlap.IsChecked() ) );
150     if( aCbTextBreak.GetState() != STATE_DONTKNOW )
151         rOutAttrs.Put( SfxBoolItem( SCHATTR_AXIS_LABEL_BREAK, aCbTextBreak.IsChecked() ) );
152     if( aCbShowDescription.GetState() != STATE_DONTKNOW )
153         rOutAttrs.Put( SfxBoolItem( SCHATTR_AXIS_SHOWDESCR, aCbShowDescription.IsChecked() ) );
154 
155     if( m_aLbTextDirection.GetSelectEntryCount() > 0 )
156         rOutAttrs.Put( SfxInt32Item( EE_PARA_WRITINGDIR, m_aLbTextDirection.GetSelectEntryValue() ) );
157 
158 	return sal_True;
159 }
160 
161 void SchAxisLabelTabPage::Reset( const SfxItemSet& rInAttrs )
162 {
163 	const SfxPoolItem* pPoolItem = NULL;
164     SfxItemState aState = SFX_ITEM_UNKNOWN;
165 
166     // show description ----------
167     aState = rInAttrs.GetItemState( SCHATTR_AXIS_SHOWDESCR, sal_False, &pPoolItem );
168     if( aState == SFX_ITEM_DONTCARE )
169     {
170         aCbShowDescription.EnableTriState( sal_True );
171         aCbShowDescription.SetState( STATE_DONTKNOW );
172     }
173     else
174     {
175         aCbShowDescription.EnableTriState( sal_False );
176         sal_Bool bCheck = sal_False;
177         if( aState == SFX_ITEM_SET )
178             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
179         aCbShowDescription.Check( bCheck );
180 
181         if( ( aState & SFX_ITEM_DEFAULT ) == 0 )
182             aCbShowDescription.Hide();
183     }
184 
185     // Rotation as orient item or in degrees ----------
186 
187     // check new degree item
188     m_nInitialDegrees = 0;
189     aState = rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, sal_False, &pPoolItem );
190     if( aState == SFX_ITEM_SET )
191         m_nInitialDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
192 
193     m_bHasInitialDegrees = aState != SFX_ITEM_DONTCARE;
194     if( m_bHasInitialDegrees )
195         aCtrlDial.SetRotation( m_nInitialDegrees );
196     else
197         aCtrlDial.SetNoRotation();
198 
199     // check stacked item
200     m_bInitialStacking = false;
201     aState = rInAttrs.GetItemState( SCHATTR_TEXT_STACKED, sal_False, &pPoolItem );
202     if( aState == SFX_ITEM_SET )
203         m_bInitialStacking = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
204 
205     m_bHasInitialStacking = aState != SFX_ITEM_DONTCARE;
206     if( m_bHasInitialDegrees )
207         aOrientHlp.SetStackedState( m_bInitialStacking ? STATE_CHECK : STATE_NOCHECK );
208     else
209         aOrientHlp.SetStackedState( STATE_DONTKNOW );
210 
211     if( rInAttrs.GetItemState( EE_PARA_WRITINGDIR, sal_True, &pPoolItem ) == SFX_ITEM_SET )
212         m_aLbTextDirection.SelectEntryValue( SvxFrameDirection(((const SvxFrameDirectionItem*)pPoolItem)->GetValue()) );
213 
214     // Text overlap ----------
215     aState = rInAttrs.GetItemState( SCHATTR_AXIS_LABEL_OVERLAP, sal_False, &pPoolItem );
216     if( aState == SFX_ITEM_DONTCARE )
217     {
218         aCbTextOverlap.EnableTriState( sal_True );
219         aCbTextOverlap.SetState( STATE_DONTKNOW );
220     }
221     else
222     {
223         aCbTextOverlap.EnableTriState( sal_False );
224         sal_Bool bCheck = sal_False;
225         if( aState == SFX_ITEM_SET )
226             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
227         aCbTextOverlap.Check( bCheck );
228 
229         if( ( aState & SFX_ITEM_DEFAULT ) == 0 )
230             aCbTextOverlap.Hide();
231     }
232 
233     // text break ----------
234     aState = rInAttrs.GetItemState( SCHATTR_AXIS_LABEL_BREAK, sal_False, &pPoolItem );
235     if( aState == SFX_ITEM_DONTCARE )
236     {
237         aCbTextBreak.EnableTriState( sal_True );
238         aCbTextBreak.SetState( STATE_DONTKNOW );
239     }
240     else
241     {
242         aCbTextBreak.EnableTriState( sal_False );
243         sal_Bool bCheck = sal_False;
244         if( aState == SFX_ITEM_SET )
245             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
246         aCbTextBreak.Check( bCheck );
247 
248         if( ( aState & SFX_ITEM_DEFAULT ) == 0 )
249         {
250             aCbTextBreak.Hide();
251             if( ! aCbTextOverlap.IsVisible() )
252                 aFlTextFlow.Hide();
253         }
254     }
255 
256     // text order ----------
257     if( m_bShowStaggeringControls )
258     {
259         aState = rInAttrs.GetItemState( SCHATTR_AXIS_LABEL_ORDER, sal_False, &pPoolItem );
260         if( aState == SFX_ITEM_SET )
261         {
262             SvxChartTextOrder eOrder = static_cast< const SvxChartTextOrderItem * >( pPoolItem )->GetValue();
263 
264             switch( eOrder )
265             {
266                 case CHTXTORDER_SIDEBYSIDE:
267                     aRbSideBySide.Check();
268                     break;
269                 case CHTXTORDER_UPDOWN:
270                     aRbUpDown.Check();
271                     break;
272                 case CHTXTORDER_DOWNUP:
273                     aRbDownUp.Check();
274                     break;
275                 case CHTXTORDER_AUTO:
276                     aRbAuto.Check();
277                     break;
278             }
279         }
280     }
281 
282     ToggleShowLabel( (void*)0 );
283 }
284 
285 void SchAxisLabelTabPage::ShowStaggeringControls( sal_Bool bShowStaggeringControls )
286 {
287     m_bShowStaggeringControls = bShowStaggeringControls;
288 
289     if( !m_bShowStaggeringControls )
290 	{
291 		aRbSideBySide.Hide();
292 		aRbUpDown.Hide();
293 		aRbDownUp.Hide();
294 		aRbAuto.Hide();
295 		aFlOrder.Hide();
296 	}
297 }
298 
299 void SchAxisLabelTabPage::SetComplexCategories( bool bComplexCategories )
300 {
301     m_bComplexCategories = bComplexCategories;
302 }
303 
304 // event handling routines
305 // -----------------------
306 
307 IMPL_LINK ( SchAxisLabelTabPage, ToggleShowLabel, void *, EMPTYARG )
308 {
309     sal_Bool bEnable = ( aCbShowDescription.GetState() != STATE_NOCHECK );
310 
311     aOrientHlp.Enable( bEnable );
312 	aFlOrder.Enable( bEnable );
313 	aRbSideBySide.Enable( bEnable );
314 	aRbUpDown.Enable( bEnable );
315 	aRbDownUp.Enable( bEnable );
316 	aRbAuto.Enable( bEnable );
317 
318 	aFlTextFlow.Enable( bEnable );
319 	aCbTextOverlap.Enable( bEnable && !m_bComplexCategories );
320 	aCbTextBreak.Enable( bEnable );
321 
322     m_aFtTextDirection.Enable( bEnable );
323     m_aLbTextDirection.Enable( bEnable );
324 
325 	return 0L;
326 }
327 //.............................................................................
328 } //namespace chart
329 //.............................................................................
330