1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "tp_AxisLabel.hxx"
21 
22 #include <chartview/ChartSfxItemIds.hxx>
23 #include <TextDirectionListBox.hxx>
24 
25 #include <svx/chrtitem.hxx>
26 #include <svx/sdangitm.hxx>
27 #include <svl/intitem.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <editeng/frmdiritem.hxx>
30 
31 namespace chart
32 {
33 
SchAxisLabelTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rInAttrs)34 SchAxisLabelTabPage::SchAxisLabelTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
35     : SfxTabPage(pPage, pController, "modules/schart/ui/tp_axisLabel.ui", "AxisLabelTabPage", &rInAttrs)
36     , m_bShowStaggeringControls( true )
37     , m_nInitialDegrees( 0 )
38     , m_bHasInitialDegrees( true )
39     , m_bInitialStacking( false )
40     , m_bHasInitialStacking( true )
41     , m_bComplexCategories( false )
42     , m_xCbShowDescription(m_xBuilder->weld_check_button("showlabelsCB"))
43     , m_xFlOrder(m_xBuilder->weld_label("orderL"))
44     , m_xRbSideBySide(m_xBuilder->weld_radio_button("tile"))
45     , m_xRbUpDown(m_xBuilder->weld_radio_button("odd"))
46     , m_xRbDownUp(m_xBuilder->weld_radio_button("even"))
47     , m_xRbAuto(m_xBuilder->weld_radio_button("auto"))
48     , m_xFlTextFlow(m_xBuilder->weld_label("textflowL"))
49     , m_xCbTextOverlap(m_xBuilder->weld_check_button("overlapCB"))
50     , m_xCbTextBreak(m_xBuilder->weld_check_button("breakCB"))
51     , m_xFtABCD(m_xBuilder->weld_label("labelABCD"))
52     , m_xFlOrient(m_xBuilder->weld_label("labelTextOrient"))
53     , m_xFtRotate(m_xBuilder->weld_label("degreeL"))
54     , m_xNfRotate(m_xBuilder->weld_metric_spin_button("OrientDegree", FieldUnit::DEGREE))
55     , m_xCbStacked(m_xBuilder->weld_check_button("stackedCB"))
56     , m_xFtTextDirection(m_xBuilder->weld_label("textdirL"))
57     , m_xLbTextDirection(new TextDirectionListBox(m_xBuilder->weld_combo_box("textdirLB")))
58     , m_xCtrlDial(new svx::DialControl)
59     , m_xCtrlDialWin(new weld::CustomWeld(*m_xBuilder, "dialCtrl", *m_xCtrlDial))
60 {
61     m_xCtrlDial->SetText(m_xFtABCD->get_label());
62     m_xCtrlDial->SetLinkedField(m_xNfRotate.get());
63     m_xCtrlDialWin->set_sensitive(true);
64     m_xNfRotate->set_sensitive(true);
65     m_xCbStacked->set_sensitive(true);
66     m_xFtRotate->set_sensitive(true);
67 
68     m_xCbStacked->connect_toggled(LINK(this, SchAxisLabelTabPage, StackedToggleHdl));
69     m_xCbShowDescription->connect_toggled(LINK(this, SchAxisLabelTabPage, ToggleShowLabel));
70 }
71 
~SchAxisLabelTabPage()72 SchAxisLabelTabPage::~SchAxisLabelTabPage()
73 {
74     m_xCtrlDialWin.reset();
75     m_xCtrlDial.reset();
76     m_xLbTextDirection.reset();
77 }
78 
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrs)79 std::unique_ptr<SfxTabPage> SchAxisLabelTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
80 {
81     return std::make_unique<SchAxisLabelTabPage>(pPage, pController, *rAttrs);
82 }
83 
FillItemSet(SfxItemSet * rOutAttrs)84 bool SchAxisLabelTabPage::FillItemSet( SfxItemSet* rOutAttrs )
85 {
86     bool bStacked = false;
87     if (m_xCbStacked->get_state() != TRISTATE_INDET )
88     {
89         bStacked = m_xCbStacked->get_state() == TRISTATE_TRUE;
90         if( !m_bHasInitialStacking || (bStacked != m_bInitialStacking) )
91             rOutAttrs->Put( SfxBoolItem( SCHATTR_TEXT_STACKED, bStacked ) );
92     }
93 
94     if( m_xCtrlDial->HasRotation() )
95     {
96         Degree100 nDegrees = bStacked ? 0_deg100 : m_xCtrlDial->GetRotation();
97         if( !m_bHasInitialDegrees || (nDegrees != m_nInitialDegrees) )
98             rOutAttrs->Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, nDegrees ) );
99     }
100 
101     if( m_bShowStaggeringControls )
102     {
103         SvxChartTextOrder eOrder = SvxChartTextOrder::SideBySide;
104         bool bRadioButtonChecked = true;
105 
106         if( m_xRbUpDown->get_active())
107             eOrder = SvxChartTextOrder::UpDown;
108         else if( m_xRbDownUp->get_active())
109             eOrder = SvxChartTextOrder::DownUp;
110         else if( m_xRbAuto->get_active())
111             eOrder = SvxChartTextOrder::Auto;
112         else if( m_xRbSideBySide->get_active())
113             eOrder = SvxChartTextOrder::SideBySide;
114         else
115             bRadioButtonChecked = false;
116 
117         if( bRadioButtonChecked )
118             rOutAttrs->Put( SvxChartTextOrderItem( eOrder, SCHATTR_AXIS_LABEL_ORDER ));
119     }
120 
121     if( m_xCbTextOverlap->get_state() != TRISTATE_INDET )
122         rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_LABEL_OVERLAP, m_xCbTextOverlap->get_active() ) );
123     if( m_xCbTextBreak->get_state() != TRISTATE_INDET )
124         rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_LABEL_BREAK, m_xCbTextBreak->get_active() ) );
125     if( m_xCbShowDescription->get_state() != TRISTATE_INDET )
126         rOutAttrs->Put( SfxBoolItem( SCHATTR_AXIS_SHOWDESCR, m_xCbShowDescription->get_active() ) );
127 
128     if (m_xLbTextDirection->get_active() != -1)
129         rOutAttrs->Put( SvxFrameDirectionItem( m_xLbTextDirection->get_active_id(), EE_PARA_WRITINGDIR ) );
130 
131     return true;
132 }
133 
Reset(const SfxItemSet * rInAttrs)134 void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs )
135 {
136     const SfxPoolItem* pPoolItem = nullptr;
137 
138     // show description
139     SfxItemState aState = rInAttrs->GetItemState( SCHATTR_AXIS_SHOWDESCR, false, &pPoolItem );
140     if( aState == SfxItemState::DONTCARE )
141     {
142         m_xCbShowDescription->set_state( TRISTATE_INDET );
143     }
144     else
145     {
146         bool bCheck = false;
147         if( aState == SfxItemState::SET )
148             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
149         m_xCbShowDescription->set_active( bCheck );
150 
151         if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
152             m_xCbShowDescription->hide();
153     }
154 
155     // Rotation as orient item or in degrees ----------
156 
157     // check new degree item
158     m_nInitialDegrees = 0_deg100;
159     aState = rInAttrs->GetItemState( SCHATTR_TEXT_DEGREES, false, &pPoolItem );
160     if( aState == SfxItemState::SET )
161         m_nInitialDegrees = static_cast< const SdrAngleItem * >( pPoolItem )->GetValue();
162 
163     m_bHasInitialDegrees = aState != SfxItemState::DONTCARE;
164     if( m_bHasInitialDegrees )
165         m_xCtrlDial->SetRotation( m_nInitialDegrees );
166     else
167         m_xCtrlDial->SetNoRotation();
168 
169     // check stacked item
170     m_bInitialStacking = false;
171     aState = rInAttrs->GetItemState( SCHATTR_TEXT_STACKED, false, &pPoolItem );
172     if( aState == SfxItemState::SET )
173         m_bInitialStacking = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
174 
175     m_bHasInitialStacking = aState != SfxItemState::DONTCARE;
176     if( m_bHasInitialDegrees )
177         m_xCbStacked->set_state(m_bInitialStacking ? TRISTATE_TRUE : TRISTATE_FALSE);
178     else
179         m_xCbStacked->set_state(TRISTATE_INDET);
180     StackedToggleHdl(*m_xCbStacked);
181 
182     if( rInAttrs->GetItemState( EE_PARA_WRITINGDIR, true, &pPoolItem ) == SfxItemState::SET )
183         m_xLbTextDirection->set_active_id( static_cast<const SvxFrameDirectionItem*>(pPoolItem)->GetValue() );
184 
185     // Text overlap ----------
186     aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_OVERLAP, false, &pPoolItem );
187     if( aState == SfxItemState::DONTCARE )
188     {
189         m_xCbTextOverlap->set_state( TRISTATE_INDET );
190     }
191     else
192     {
193         bool bCheck = false;
194         if( aState == SfxItemState::SET )
195             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
196         m_xCbTextOverlap->set_active( bCheck );
197 
198         if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
199             m_xCbTextOverlap->hide();
200     }
201 
202     // text break ----------
203     aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_BREAK, false, &pPoolItem );
204     if( aState == SfxItemState::DONTCARE )
205     {
206         m_xCbTextBreak->set_state( TRISTATE_INDET );
207     }
208     else
209     {
210         bool bCheck = false;
211         if( aState == SfxItemState::SET )
212             bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
213         m_xCbTextBreak->set_active( bCheck );
214 
215         if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET )
216         {
217             m_xCbTextBreak->hide();
218             if( ! m_xCbTextOverlap->get_visible() )
219                 m_xFlTextFlow->hide();
220         }
221     }
222 
223     // text order ----------
224     if( m_bShowStaggeringControls )
225     {
226         aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_ORDER, false, &pPoolItem );
227         if( aState == SfxItemState::SET )
228         {
229             SvxChartTextOrder eOrder = static_cast< const SvxChartTextOrderItem * >( pPoolItem )->GetValue();
230 
231             switch( eOrder )
232             {
233                 case SvxChartTextOrder::SideBySide:
234                     m_xRbSideBySide->set_active(true);
235                     break;
236                 case SvxChartTextOrder::UpDown:
237                     m_xRbUpDown->set_active(true);
238                     break;
239                 case SvxChartTextOrder::DownUp:
240                     m_xRbDownUp->set_active(true);
241                     break;
242                 case SvxChartTextOrder::Auto:
243                     m_xRbAuto->set_active(true);
244                     break;
245             }
246         }
247     }
248 
249     ToggleShowLabel(*m_xCbShowDescription);
250 }
251 
ShowStaggeringControls(bool bShowStaggeringControls)252 void SchAxisLabelTabPage::ShowStaggeringControls( bool bShowStaggeringControls )
253 {
254     m_bShowStaggeringControls = bShowStaggeringControls;
255 
256     if( !m_bShowStaggeringControls )
257     {
258         m_xRbSideBySide->hide();
259         m_xRbUpDown->hide();
260         m_xRbDownUp->hide();
261         m_xRbAuto->hide();
262         m_xFlOrder->hide();
263     }
264 }
265 
SetComplexCategories(bool bComplexCategories)266 void SchAxisLabelTabPage::SetComplexCategories( bool bComplexCategories )
267 {
268     m_bComplexCategories = bComplexCategories;
269 }
270 
271 // event handling routines
272 
IMPL_LINK_NOARG(SchAxisLabelTabPage,StackedToggleHdl,weld::Toggleable &,void)273 IMPL_LINK_NOARG(SchAxisLabelTabPage, StackedToggleHdl, weld::Toggleable&, void)
274 {
275     bool bActive = m_xCbStacked->get_active() && m_xCbStacked->get_sensitive();
276     m_xNfRotate->set_sensitive(!bActive);
277     m_xCtrlDialWin->set_sensitive(!bActive);
278     m_xCtrlDial->StyleUpdated();
279     m_xFtRotate->set_sensitive(!bActive);
280 }
281 
IMPL_LINK_NOARG(SchAxisLabelTabPage,ToggleShowLabel,weld::Toggleable &,void)282 IMPL_LINK_NOARG(SchAxisLabelTabPage, ToggleShowLabel, weld::Toggleable&, void)
283 {
284     bool bEnable = ( m_xCbShowDescription->get_state() != TRISTATE_FALSE );
285 
286     m_xCbStacked->set_sensitive(bEnable);
287     StackedToggleHdl(*m_xCbStacked);
288 
289     m_xFlOrder->set_sensitive( bEnable );
290     m_xRbSideBySide->set_sensitive( bEnable );
291     m_xRbUpDown->set_sensitive( bEnable );
292     m_xRbDownUp->set_sensitive( bEnable );
293     m_xRbAuto->set_sensitive( bEnable );
294 
295     m_xFlTextFlow->set_sensitive( bEnable );
296     m_xCbTextOverlap->set_sensitive( bEnable && !m_bComplexCategories );
297     m_xCbTextBreak->set_sensitive( bEnable );
298 
299     m_xFtTextDirection->set_sensitive( bEnable );
300     m_xLbTextDirection->set_sensitive( bEnable );
301 }
302 } //namespace chart
303 
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
305