| 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 <editeng/eeitem.hxx> |
| 28 |
#include <editeng/frmdiritem.hxx> |
| 29 |
|
| 30 |
namespace chart |
| 31 |
{ |
| 32 |
|
| 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)) |
| 58 |
{ |
| 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); |
| 65 |
|
| 66 |
m_xCbStacked->connect_toggled(LINK(this, SchAxisLabelTabPage, StackedToggleHdl)); |
| 67 |
m_xCbShowDescription->connect_toggled(LINK(this, SchAxisLabelTabPage, ToggleShowLabel)); |
| 68 |
} |
| 69 |
|
| 70 |
SchAxisLabelTabPage::~SchAxisLabelTabPage() |
| 71 |
{ |
| 72 |
m_xCtrlDialWin.reset(); |
| 73 |
m_xCtrlDial.reset(); |
| 74 |
} |
| 75 |
|
| 76 |
std::unique_ptr<SfxTabPage> SchAxisLabelTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs) |
| 77 |
{ |
| 78 |
return std::make_unique<SchAxisLabelTabPage>(pPage, pController, *rAttrs); |
| 79 |
} |
| 80 |
|
| 81 |
bool SchAxisLabelTabPage::FillItemSet( SfxItemSet* rOutAttrs ) |
| 82 |
{ |
| 83 |
bool bStacked = false; |
| 84 |
if (m_xCbStacked->get_state() != TRISTATE_INDET ) |
| 85 |
{ |
| 86 |
bStacked = m_xCbStacked->get_state() == TRISTATE_TRUE; |
| 87 |
if( !m_bHasInitialStacking || (bStacked != m_bInitialStacking) ) |
| 88 |
rOutAttrs->Put( SfxBoolItem( SCHATTR_TEXT_STACKED, bStacked ) ); |
| 89 |
} |
| 90 |
|
| 91 |
if( m_xCtrlDial->HasRotation() ) |
| 92 |
{ |
| 93 |
Degree100 nDegrees = bStacked ? 0_deg100 : m_xCtrlDial->GetRotation(); |
| 94 |
if( !m_bHasInitialDegrees || (nDegrees != m_nInitialDegrees) ) |
| 95 |
rOutAttrs->Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, nDegrees ) ); |
| 96 |
} |
| 97 |
|
| 98 |
if( m_bShowStaggeringControls ) |
| 99 |
{ |
| 100 |
SvxChartTextOrder eOrder = SvxChartTextOrder::SideBySide; |
| 101 |
bool bRadioButtonChecked = true; |
| 102 |
|
| 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; |
| 113 |
|
| 114 |
if( bRadioButtonChecked ) |
| 115 |
rOutAttrs->Put( SvxChartTextOrderItem( eOrder, SCHATTR_AXIS_LABEL_ORDER )); |
| 116 |
} |
| 117 |
|
| 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() ) ); |
| 124 |
|
| 125 |
if (m_aLbTextDirection.get_active() != -1) |
| 126 |
rOutAttrs->Put( SvxFrameDirectionItem( m_aLbTextDirection.get_active_id(), EE_PARA_WRITINGDIR ) ); |
| 127 |
|
| 128 |
return true; |
| 129 |
} |
| 130 |
|
| 131 |
void SchAxisLabelTabPage::Reset( const SfxItemSet* rInAttrs ) |
| 132 |
{ |
| 133 |
const SfxPoolItem* pPoolItem = nullptr; |
| 134 |
|
| 135 |
// show description |
| 136 |
SfxItemState aState = rInAttrs->GetItemState( SCHATTR_AXIS_SHOWDESCR, false, &pPoolItem ); |
| 137 |
if( aState == SfxItemState::INVALID ) |
| 138 |
{ |
| 139 |
m_xCbShowDescription->set_state( TRISTATE_INDET ); |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
bool bCheck = false; |
| 144 |
if( aState == SfxItemState::SET ) |
| 145 |
bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); |
| 146 |
m_xCbShowDescription->set_active( bCheck ); |
| 147 |
|
| 148 |
if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET ) |
| 149 |
m_xCbShowDescription->hide(); |
| 150 |
} |
| 151 |
|
| 152 |
// Rotation as orient item or in degrees ---------- |
| 153 |
|
| 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(); |
| 159 |
|
| 160 |
m_bHasInitialDegrees = aState != SfxItemState::INVALID; |
| 161 |
if( m_bHasInitialDegrees ) |
| 162 |
m_xCtrlDial->SetRotation( m_nInitialDegrees ); |
| 163 |
else |
| 164 |
m_xCtrlDial->SetNoRotation(); |
| 165 |
|
| 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(); |
| 171 |
|
| 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); |
| 178 |
|
| 179 |
if( const SvxFrameDirectionItem* pDirectionItem = rInAttrs->GetItemIfSet( EE_PARA_WRITINGDIR ) ) |
| 180 |
m_aLbTextDirection.set_active_id( pDirectionItem->GetValue() ); |
| 181 |
|
| 182 |
// Text overlap ---------- |
| 183 |
aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_OVERLAP, false, &pPoolItem ); |
| 184 |
if( aState == SfxItemState::INVALID ) |
| 185 |
{ |
| 186 |
m_xCbTextOverlap->set_state( TRISTATE_INDET ); |
| 187 |
} |
| 188 |
else |
| 189 |
{ |
| 190 |
bool bCheck = false; |
| 191 |
if( aState == SfxItemState::SET ) |
| 192 |
bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); |
| 193 |
m_xCbTextOverlap->set_active( bCheck ); |
| 194 |
|
| 195 |
if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET ) |
| 196 |
m_xCbTextOverlap->hide(); |
| 197 |
} |
| 198 |
|
| 199 |
// text break ---------- |
| 200 |
aState = rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_BREAK, false, &pPoolItem ); |
| 201 |
if( aState == SfxItemState::INVALID ) |
| 202 |
{ |
| 203 |
m_xCbTextBreak->set_state( TRISTATE_INDET ); |
| 204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
bool bCheck = false; |
| 208 |
if( aState == SfxItemState::SET ) |
| 209 |
bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); |
| 210 |
m_xCbTextBreak->set_active( bCheck ); |
| 211 |
|
| 212 |
if( aState != SfxItemState::DEFAULT && aState != SfxItemState::SET ) |
| 213 |
{ |
| 214 |
m_xCbTextBreak->hide(); |
| 215 |
if( ! m_xCbTextOverlap->get_visible() ) |
| 216 |
m_xFlTextFlow->hide(); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
// text order ---------- |
| 221 |
if( m_bShowStaggeringControls ) |
| 222 |
{ |
| 223 |
if( const SvxChartTextOrderItem* pOrderItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_LABEL_ORDER, false ) ) |
| 224 |
{ |
| 225 |
SvxChartTextOrder eOrder = pOrderItem->GetValue(); |
| 226 |
|
| 227 |
switch( eOrder ) |
| 228 |
{ |
| 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; |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
ToggleShowLabel(*m_xCbShowDescription); |
| 246 |
} |
| 247 |
|
| 248 |
void SchAxisLabelTabPage::ShowStaggeringControls( bool bShowStaggeringControls ) |
| 249 |
{ |
| 250 |
m_bShowStaggeringControls = bShowStaggeringControls; |
| 251 |
|
| 252 |
if( !m_bShowStaggeringControls ) |
| 253 |
{ |
| 254 |
m_xRbSideBySide->hide(); |
| 255 |
m_xRbUpDown->hide(); |
| 256 |
m_xRbDownUp->hide(); |
| 257 |
m_xRbAuto->hide(); |
| 258 |
m_xFlOrder->hide(); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
void SchAxisLabelTabPage::SetComplexCategories( bool bComplexCategories ) |
| 263 |
{ |
| 264 |
m_bComplexCategories = bComplexCategories; |
| 265 |
} |
| 266 |
|
| 267 |
// event handling routines |
| 268 |
|
| 269 |
IMPL_LINK_NOARG(SchAxisLabelTabPage, StackedToggleHdl, weld::Toggleable&, void) |
| 270 |
{ |
| 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); |
| 276 |
} |
| 277 |
|
| 278 |
IMPL_LINK_NOARG(SchAxisLabelTabPage, ToggleShowLabel, weld::Toggleable&, void) |
| 279 |
{ |
| 280 |
bool bEnable = ( m_xCbShowDescription->get_state() != TRISTATE_FALSE ); |
| 281 |
|
| 282 |
m_xCbStacked->set_sensitive(bEnable); |
| 283 |
StackedToggleHdl(*m_xCbStacked); |
| 284 |
|
| 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 ); |
| 290 |
|
| 291 |
m_xFlTextFlow->set_sensitive( bEnable ); |
| 292 |
m_xCbTextOverlap->set_sensitive( bEnable && !m_bComplexCategories ); |
| 293 |
m_xCbTextBreak->set_sensitive( bEnable ); |
| 294 |
|
| 295 |
m_xFtTextDirection->set_sensitive( bEnable ); |
| 296 |
m_aLbTextDirection.set_sensitive( bEnable ); |
| 297 |
} |
| 298 |
} //namespace chart |
| 299 |
|
| 300 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |