cid#1607362 Overflowed constant
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_AxisLabel.cxx
blob396086bb46a638c7ac3b09379ae2e929288fffe1
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 <svx/sdangitm.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, u"modules/schart/ui/tp_axisLabel.ui"_ustr, u"AxisLabelTabPage"_ustr, &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(u"showlabelsCB"_ustr))
42 , m_xFlOrder(m_xBuilder->weld_label(u"orderL"_ustr))
43 , m_xRbSideBySide(m_xBuilder->weld_radio_button(u"tile"_ustr))
44 , m_xRbUpDown(m_xBuilder->weld_radio_button(u"odd"_ustr))
45 , m_xRbDownUp(m_xBuilder->weld_radio_button(u"even"_ustr))
46 , m_xRbAuto(m_xBuilder->weld_radio_button(u"auto"_ustr))
47 , m_xFlTextFlow(m_xBuilder->weld_label(u"textflowL"_ustr))
48 , m_xCbTextOverlap(m_xBuilder->weld_check_button(u"overlapCB"_ustr))
49 , m_xCbTextBreak(m_xBuilder->weld_check_button(u"breakCB"_ustr))
50 , m_xFtABCD(m_xBuilder->weld_label(u"labelABCD"_ustr))
51 , m_xFtRotate(m_xBuilder->weld_label(u"degreeL"_ustr))
52 , m_xNfRotate(m_xBuilder->weld_metric_spin_button(u"OrientDegree"_ustr, FieldUnit::DEGREE))
53 , m_xCbStacked(m_xBuilder->weld_check_button(u"stackedCB"_ustr))
54 , m_xFtTextDirection(m_xBuilder->weld_label(u"textdirL"_ustr))
55 , m_aLbTextDirection(m_xBuilder->weld_combo_box(u"textdirLB"_ustr))
56 , m_xCtrlDial(new svx::DialControl)
57 , m_xCtrlDialWin(new weld::CustomWeld(*m_xBuilder, u"dialCtrl"_ustr, *m_xCtrlDial))
59 m_xCtrlDial->SetText(m_xFtABCD->get_label());
60 m_xCtrlDial->SetLinkedField(m_xNfRotate.get());
61 m_xCtrlDialWin->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_xCtrlDialWin.reset();
73 m_xCtrlDial.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_xCtrlDial->HasRotation() )
93 Degree100 nDegrees = bStacked ? 0_deg100 : m_xCtrlDial->GetRotation();
94 if( !m_bHasInitialDegrees || (nDegrees != m_nInitialDegrees) )
95 rOutAttrs->Put( SdrAngleItem( 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_aLbTextDirection.get_active() != -1)
126 rOutAttrs->Put( SvxFrameDirectionItem( m_aLbTextDirection.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::INVALID )
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_deg100;
156 aState = rInAttrs->GetItemState( SCHATTR_TEXT_DEGREES, false, &pPoolItem );
157 if( aState == SfxItemState::SET )
158 m_nInitialDegrees = static_cast< const SdrAngleItem * >( pPoolItem )->GetValue();
160 m_bHasInitialDegrees = aState != SfxItemState::INVALID;
161 if( m_bHasInitialDegrees )
162 m_xCtrlDial->SetRotation( m_nInitialDegrees );
163 else
164 m_xCtrlDial->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::INVALID;
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( const SvxFrameDirectionItem* pDirectionItem = rInAttrs->GetItemIfSet( EE_PARA_WRITINGDIR ) )
180 m_aLbTextDirection.set_active_id( pDirectionItem->GetValue() );
182 // Text overlap ----------
183 aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_OVERLAP, false, &pPoolItem );
184 if( aState == SfxItemState::INVALID )
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::INVALID )
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 if( const SvxChartTextOrderItem* pOrderItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_LABEL_ORDER, false ) )
225 SvxChartTextOrder eOrder = pOrderItem->GetValue();
227 switch( eOrder )
229 case SvxChartTextOrder::SideBySide:
230 m_xRbSideBySide->set_active(true);
231 break;
232 case SvxChartTextOrder::UpDown:
233 m_xRbUpDown->set_active(true);
234 break;
235 case SvxChartTextOrder::DownUp:
236 m_xRbDownUp->set_active(true);
237 break;
238 case SvxChartTextOrder::Auto:
239 m_xRbAuto->set_active(true);
240 break;
245 ToggleShowLabel(*m_xCbShowDescription);
248 void SchAxisLabelTabPage::ShowStaggeringControls( bool bShowStaggeringControls )
250 m_bShowStaggeringControls = bShowStaggeringControls;
252 if( !m_bShowStaggeringControls )
254 m_xRbSideBySide->hide();
255 m_xRbUpDown->hide();
256 m_xRbDownUp->hide();
257 m_xRbAuto->hide();
258 m_xFlOrder->hide();
262 void SchAxisLabelTabPage::SetComplexCategories( bool bComplexCategories )
264 m_bComplexCategories = bComplexCategories;
267 // event handling routines
269 IMPL_LINK_NOARG(SchAxisLabelTabPage, StackedToggleHdl, weld::Toggleable&, void)
271 bool bActive = m_xCbStacked->get_active() && m_xCbStacked->get_sensitive();
272 m_xNfRotate->set_sensitive(!bActive);
273 m_xCtrlDialWin->set_sensitive(!bActive);
274 m_xCtrlDial->StyleUpdated();
275 m_xFtRotate->set_sensitive(!bActive);
278 IMPL_LINK_NOARG(SchAxisLabelTabPage, ToggleShowLabel, weld::Toggleable&, void)
280 bool bEnable = ( m_xCbShowDescription->get_state() != TRISTATE_FALSE );
282 m_xCbStacked->set_sensitive(bEnable);
283 StackedToggleHdl(*m_xCbStacked);
285 m_xFlOrder->set_sensitive( bEnable );
286 m_xRbSideBySide->set_sensitive( bEnable );
287 m_xRbUpDown->set_sensitive( bEnable );
288 m_xRbDownUp->set_sensitive( bEnable );
289 m_xRbAuto->set_sensitive( bEnable );
291 m_xFlTextFlow->set_sensitive( bEnable );
292 m_xCbTextOverlap->set_sensitive( bEnable && !m_bComplexCategories );
293 m_xCbTextBreak->set_sensitive( bEnable );
295 m_xFtTextDirection->set_sensitive( bEnable );
296 m_aLbTextDirection.set_sensitive( bEnable );
298 } //namespace chart
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */