Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_AxisLabel.cxx
blobdfc6bf887878bbb2f1f2f3c2161877646a467e82
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 "tp_AxisLabel.hxx"
22 #include <chartview/ChartSfxItemIds.hxx>
23 #include <TextDirectionListBox.hxx>
25 #include <svx/chrtitem.hxx>
26 #include <svl/intitem.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/frmdiritem.hxx>
30 namespace chart
33 SchAxisLabelTabPage::SchAxisLabelTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
34 : SfxTabPage(pPage, pController, "modules/schart/ui/tp_axisLabel.ui", "AxisLabelTabPage", &rInAttrs)
35 , m_bShowStaggeringControls( true )
36 , m_nInitialDegrees( 0 )
37 , m_bHasInitialDegrees( true )
38 , m_bInitialStacking( false )
39 , m_bHasInitialStacking( true )
40 , m_bComplexCategories( false )
41 , m_xCbShowDescription(m_xBuilder->weld_check_button("showlabelsCB"))
42 , m_xFlOrder(m_xBuilder->weld_label("orderL"))
43 , m_xRbSideBySide(m_xBuilder->weld_radio_button("tile"))
44 , m_xRbUpDown(m_xBuilder->weld_radio_button("odd"))
45 , m_xRbDownUp(m_xBuilder->weld_radio_button("even"))
46 , m_xRbAuto(m_xBuilder->weld_radio_button("auto"))
47 , m_xFlTextFlow(m_xBuilder->weld_label("textflowL"))
48 , m_xCbTextOverlap(m_xBuilder->weld_check_button("overlapCB"))
49 , m_xCbTextBreak(m_xBuilder->weld_check_button("breakCB"))
50 , m_xFtABCD(m_xBuilder->weld_label("labelABCD"))
51 , m_xFlOrient(m_xBuilder->weld_label("labelTextOrient"))
52 , m_xFtRotate(m_xBuilder->weld_label("degreeL"))
53 , m_xNfRotate(m_xBuilder->weld_spin_button("OrientDegree"))
54 , m_xCbStacked(m_xBuilder->weld_check_button("stackedCB"))
55 , m_xFtTextDirection(m_xBuilder->weld_label("textdirL"))
56 , m_xLbTextDirection(new TextDirectionListBox(m_xBuilder->weld_combo_box("textdirLB")))
57 , m_xCtrlDial(new weld::CustomWeld(*m_xBuilder, "dialCtrl", m_aCtrlDial))
59 m_aCtrlDial.SetText(m_xFtABCD->get_label());
60 m_aCtrlDial.SetLinkedField(m_xNfRotate.get());
61 m_xCtrlDial->set_sensitive(true);
62 m_xNfRotate->set_sensitive(true);
63 m_xCbStacked->set_sensitive(true);
64 m_xFtRotate->set_sensitive(true);
66 m_xCbStacked->connect_toggled(LINK(this, SchAxisLabelTabPage, StackedToggleHdl));
67 m_xCbShowDescription->connect_toggled(LINK(this, SchAxisLabelTabPage, ToggleShowLabel));
70 SchAxisLabelTabPage::~SchAxisLabelTabPage()
72 m_xCtrlDial.reset();
73 m_xLbTextDirection.reset();
76 std::unique_ptr<SfxTabPage> SchAxisLabelTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
78 return std::make_unique<SchAxisLabelTabPage>(pPage, pController, *rAttrs);
81 bool SchAxisLabelTabPage::FillItemSet( SfxItemSet* rOutAttrs )
83 bool bStacked = false;
84 if (m_xCbStacked->get_state() != TRISTATE_INDET )
86 bStacked = m_xCbStacked->get_state() == TRISTATE_TRUE;
87 if( !m_bHasInitialStacking || (bStacked != m_bInitialStacking) )
88 rOutAttrs->Put( SfxBoolItem( SCHATTR_TEXT_STACKED, bStacked ) );
91 if( m_aCtrlDial.HasRotation() )
93 sal_Int32 nDegrees = bStacked ? 0 : m_aCtrlDial.GetRotation();
94 if( !m_bHasInitialDegrees || (nDegrees != m_nInitialDegrees) )
95 rOutAttrs->Put( SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
98 if( m_bShowStaggeringControls )
100 SvxChartTextOrder eOrder = SvxChartTextOrder::SideBySide;
101 bool bRadioButtonChecked = true;
103 if( m_xRbUpDown->get_active())
104 eOrder = SvxChartTextOrder::UpDown;
105 else if( m_xRbDownUp->get_active())
106 eOrder = SvxChartTextOrder::DownUp;
107 else if( m_xRbAuto->get_active())
108 eOrder = SvxChartTextOrder::Auto;
109 else if( m_xRbSideBySide->get_active())
110 eOrder = SvxChartTextOrder::SideBySide;
111 else
112 bRadioButtonChecked = false;
114 if( bRadioButtonChecked )
115 rOutAttrs->Put( SvxChartTextOrderItem( eOrder, SCHATTR_AXIS_LABEL_ORDER ));
118 if( m_xCbTextOverlap->get_state() != TRISTATE_INDET )
119 rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_LABEL_OVERLAP, m_xCbTextOverlap->get_active() ) );
120 if( m_xCbTextBreak->get_state() != TRISTATE_INDET )
121 rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_LABEL_BREAK, m_xCbTextBreak->get_active() ) );
122 if( m_xCbShowDescription->get_state() != TRISTATE_INDET )
123 rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_SHOWDESCR, m_xCbShowDescription->get_active() ) );
125 if (m_xLbTextDirection->get_active() != -1)
126 rOutAttrs->Put( SvxFrameDirectionItem( m_xLbTextDirection->get_active_id(), EE_PARA_WRITINGDIR ) );
128 return true;
131 void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs )
133 const SfxPoolItem* pPoolItem = nullptr;
135 // show description
136 SfxItemState aState = rInAttrs->GetItemState( SCHATTR_AXIS_SHOWDESCR, false, &pPoolItem );
137 if( aState == SfxItemState::DONTCARE )
139 m_xCbShowDescription->set_state( TRISTATE_INDET );
141 else
143 bool bCheck = false;
144 if( aState == SfxItemState::SET )
145 bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
146 m_xCbShowDescription->set_active( bCheck );
148 if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
149 m_xCbShowDescription->hide();
152 // Rotation as orient item or in degrees ----------
154 // check new degree item
155 m_nInitialDegrees = 0;
156 aState = rInAttrs->GetItemState( SCHATTR_TEXT_DEGREES, false, &pPoolItem );
157 if( aState == SfxItemState::SET )
158 m_nInitialDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
160 m_bHasInitialDegrees = aState != SfxItemState::DONTCARE;
161 if( m_bHasInitialDegrees )
162 m_aCtrlDial.SetRotation( m_nInitialDegrees );
163 else
164 m_aCtrlDial.SetNoRotation();
166 // check stacked item
167 m_bInitialStacking = false;
168 aState = rInAttrs->GetItemState( SCHATTR_TEXT_STACKED, false, &pPoolItem );
169 if( aState == SfxItemState::SET )
170 m_bInitialStacking = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
172 m_bHasInitialStacking = aState != SfxItemState::DONTCARE;
173 if( m_bHasInitialDegrees )
174 m_xCbStacked->set_state(m_bInitialStacking ? TRISTATE_TRUE : TRISTATE_FALSE);
175 else
176 m_xCbStacked->set_state(TRISTATE_INDET);
177 StackedToggleHdl(*m_xCbStacked);
179 if( rInAttrs->GetItemState( EE_PARA_WRITINGDIR, true, &pPoolItem ) == SfxItemState::SET )
180 m_xLbTextDirection->set_active_id( static_cast<const SvxFrameDirectionItem*>(pPoolItem)->GetValue() );
182 // Text overlap ----------
183 aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_OVERLAP, false, &pPoolItem );
184 if( aState == SfxItemState::DONTCARE )
186 m_xCbTextOverlap->set_state( TRISTATE_INDET );
188 else
190 bool bCheck = false;
191 if( aState == SfxItemState::SET )
192 bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
193 m_xCbTextOverlap->set_active( bCheck );
195 if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
196 m_xCbTextOverlap->hide();
199 // text break ----------
200 aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_BREAK, false, &pPoolItem );
201 if( aState == SfxItemState::DONTCARE )
203 m_xCbTextBreak->set_state( TRISTATE_INDET );
205 else
207 bool bCheck = false;
208 if( aState == SfxItemState::SET )
209 bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
210 m_xCbTextBreak->set_active( bCheck );
212 if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
214 m_xCbTextBreak->hide();
215 if( ! m_xCbTextOverlap->get_visible() )
216 m_xFlTextFlow->hide();
220 // text order ----------
221 if( m_bShowStaggeringControls )
223 aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_ORDER, false, &pPoolItem );
224 if( aState == SfxItemState::SET )
226 SvxChartTextOrder eOrder = static_cast< const SvxChartTextOrderItem * >( pPoolItem )->GetValue();
228 switch( eOrder )
230 case SvxChartTextOrder::SideBySide:
231 m_xRbSideBySide->set_active(true);
232 break;
233 case SvxChartTextOrder::UpDown:
234 m_xRbUpDown->set_active(true);
235 break;
236 case SvxChartTextOrder::DownUp:
237 m_xRbDownUp->set_active(true);
238 break;
239 case SvxChartTextOrder::Auto:
240 m_xRbAuto->set_active(true);
241 break;
246 ToggleShowLabel(*m_xCbShowDescription);
249 void SchAxisLabelTabPage::ShowStaggeringControls( bool bShowStaggeringControls )
251 m_bShowStaggeringControls = bShowStaggeringControls;
253 if( !m_bShowStaggeringControls )
255 m_xRbSideBySide->hide();
256 m_xRbUpDown->hide();
257 m_xRbDownUp->hide();
258 m_xRbAuto->hide();
259 m_xFlOrder->hide();
263 void SchAxisLabelTabPage::SetComplexCategories( bool bComplexCategories )
265 m_bComplexCategories = bComplexCategories;
268 // event handling routines
270 IMPL_LINK_NOARG(SchAxisLabelTabPage, StackedToggleHdl, weld::ToggleButton&, void)
272 bool bActive = m_xCbStacked->get_active() && m_xCbStacked->get_sensitive();
273 m_xNfRotate->set_sensitive(!bActive);
274 m_xCtrlDial->set_sensitive(!bActive);
275 m_aCtrlDial.StyleUpdated();
276 m_xFtRotate->set_sensitive(!bActive);
279 IMPL_LINK_NOARG(SchAxisLabelTabPage, ToggleShowLabel, weld::ToggleButton&, void)
281 bool bEnable = ( m_xCbShowDescription->get_state() != TRISTATE_FALSE );
283 m_xCbStacked->set_sensitive(bEnable);
284 StackedToggleHdl(*m_xCbStacked);
286 m_xFlOrder->set_sensitive( bEnable );
287 m_xRbSideBySide->set_sensitive( bEnable );
288 m_xRbUpDown->set_sensitive( bEnable );
289 m_xRbDownUp->set_sensitive( bEnable );
290 m_xRbAuto->set_sensitive( bEnable );
292 m_xFlTextFlow->set_sensitive( bEnable );
293 m_xCbTextOverlap->set_sensitive( bEnable && !m_bComplexCategories );
294 m_xCbTextBreak->set_sensitive( bEnable );
296 m_xFtTextDirection->set_sensitive( bEnable );
297 m_xLbTextDirection->set_sensitive( bEnable );
299 } //namespace chart
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */