| 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_AxisPositions.hxx" |
| 21 |
|
| 22 |
#include <chartview/ChartSfxItemIds.hxx> |
| 23 |
#include <AxisHelper.hxx> |
| 24 |
|
| 25 |
#include <rtl/math.hxx> |
| 26 |
#include <svx/chrtitem.hxx> |
| 27 |
#include <svl/intitem.hxx> |
| 28 |
#include <vcl/formatter.hxx> |
| 29 |
|
| 30 |
using namespace ::com::sun::star; |
| 31 |
|
| 32 |
namespace chart |
| 33 |
{ |
| 34 |
|
| 35 |
AxisPositionsTabPage::AxisPositionsTabPage(weld::Container* pPage, weld::DialogController* pController,const SfxItemSet& rInAttrs) |
| 36 |
: SfxTabPage(pPage, pController, u"modules/schart/ui/tp_AxisPositions.ui"_ustr, u"tp_AxisPositions"_ustr, &rInAttrs) |
| 37 |
, m_pNumFormatter(nullptr) |
| 38 |
, m_bCrossingAxisIsCategoryAxis(false) |
| 39 |
, m_bSupportAxisPositioning(false) |
| 40 |
, m_bSupportCategoryPositioning(false) |
| 41 |
, m_xFL_AxisLine(m_xBuilder->weld_frame(u"FL_AXIS_LINE"_ustr)) |
| 42 |
, m_xLB_CrossesAt(m_xBuilder->weld_combo_box(u"LB_CROSSES_OTHER_AXIS_AT"_ustr)) |
| 43 |
, m_xED_CrossesAt(m_xBuilder->weld_formatted_spin_button(u"EDT_CROSSES_OTHER_AXIS_AT"_ustr)) |
| 44 |
, m_xED_CrossesAtCategory(m_xBuilder->weld_combo_box( u"EDT_CROSSES_OTHER_AXIS_AT_CATEGORY"_ustr)) |
| 45 |
, m_xFL_Position(m_xBuilder->weld_frame(u"FL_POSITION"_ustr)) |
| 46 |
, m_xRB_On(m_xBuilder->weld_radio_button(u"RB_ON"_ustr)) |
| 47 |
, m_xRB_Between(m_xBuilder->weld_radio_button(u"RB_BETWEEN"_ustr)) |
| 48 |
, m_xFL_Labels(m_xBuilder->weld_frame(u"FL_LABELS"_ustr)) |
| 49 |
, m_xLB_PlaceLabels(m_xBuilder->weld_combo_box(u"LB_PLACE_LABELS"_ustr)) |
| 50 |
, m_xCB_TicksInner(m_xBuilder->weld_check_button(u"CB_TICKS_INNER"_ustr)) |
| 51 |
, m_xCB_TicksOuter(m_xBuilder->weld_check_button(u"CB_TICKS_OUTER"_ustr)) |
| 52 |
, m_xCB_MinorInner(m_xBuilder->weld_check_button(u"CB_MINOR_INNER"_ustr)) |
| 53 |
, m_xCB_MinorOuter(m_xBuilder->weld_check_button(u"CB_MINOR_OUTER"_ustr)) |
| 54 |
, m_xBxPlaceTicks(m_xBuilder->weld_widget(u"boxPLACE_TICKS"_ustr)) |
| 55 |
, m_xLB_PlaceTicks(m_xBuilder->weld_combo_box(u"LB_PLACE_TICKS"_ustr)) |
| 56 |
{ |
| 57 |
m_xLB_CrossesAt->connect_changed(LINK(this, AxisPositionsTabPage, CrossesAtSelectHdl)); |
| 58 |
m_xLB_PlaceLabels->connect_changed(LINK(this, AxisPositionsTabPage, PlaceLabelsSelectHdl)); |
| 59 |
|
| 60 |
Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
| 61 |
rCrossFormatter.ClearMinValue(); |
| 62 |
rCrossFormatter.ClearMaxValue(); |
| 63 |
Formatter& rDistanceFormatter = m_xED_CrossesAt->GetFormatter(); |
| 64 |
rDistanceFormatter.ClearMinValue(); |
| 65 |
rDistanceFormatter.ClearMaxValue(); |
| 66 |
} |
| 67 |
|
| 68 |
AxisPositionsTabPage::~AxisPositionsTabPage() |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
std::unique_ptr<SfxTabPage> AxisPositionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs) |
| 73 |
{ |
| 74 |
return std::make_unique<AxisPositionsTabPage>(pPage, pController, *rOutAttrs); |
| 75 |
} |
| 76 |
|
| 77 |
bool AxisPositionsTabPage::FillItemSet(SfxItemSet* rOutAttrs) |
| 78 |
{ |
| 79 |
// axis line |
| 80 |
sal_Int32 nPos = m_xLB_CrossesAt->get_active(); |
| 81 |
rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 )); |
| 82 |
if( nPos==2 ) |
| 83 |
{ |
| 84 |
Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
| 85 |
double fCrossover = rCrossFormatter.GetValue(); |
| 86 |
if( m_bCrossingAxisIsCategoryAxis ) |
| 87 |
fCrossover = m_xED_CrossesAtCategory->get_active()+1; |
| 88 |
rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE)); |
| 89 |
} |
| 90 |
|
| 91 |
// shifted category position |
| 92 |
if (m_xFL_Position->get_visible()) |
| 93 |
rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION, m_xRB_Between->get_active())); |
| 94 |
|
| 95 |
// labels |
| 96 |
sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active(); |
| 97 |
if (nLabelPos != -1) |
| 98 |
rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos )); |
| 99 |
|
| 100 |
// tick marks |
| 101 |
sal_Int32 nTicks=0; |
| 102 |
sal_Int32 nMinorTicks=0; |
| 103 |
|
| 104 |
if(m_xCB_MinorInner->get_active()) |
| 105 |
AFTicks::setFlagFor(nMinorTicks, AxisTicksAtr::Inner); |
| 106 |
if(m_xCB_MinorOuter->get_active()) |
| 107 |
AFTicks::setFlagFor(nMinorTicks, AxisTicksAtr::Outer); |
| 108 |
if(m_xCB_TicksInner->get_active()) |
| 109 |
AFTicks::setFlagFor(nTicks, AxisTicksAtr::Inner); |
| 110 |
if(m_xCB_TicksOuter->get_active()) |
| 111 |
AFTicks::setFlagFor(nTicks, AxisTicksAtr::Outer); |
| 112 |
|
| 113 |
rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks)); |
| 114 |
rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks)); |
| 115 |
|
| 116 |
sal_Int32 nMarkPos = m_xLB_PlaceTicks->get_active(); |
| 117 |
if (nMarkPos != -1) |
| 118 |
rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos )); |
| 119 |
|
| 120 |
return true; |
| 121 |
} |
| 122 |
|
| 123 |
void AxisPositionsTabPage::Reset(const SfxItemSet* rInAttrs) |
| 124 |
{ |
| 125 |
//init and enable controls |
| 126 |
m_xED_CrossesAt->set_visible( !m_bCrossingAxisIsCategoryAxis ); |
| 127 |
m_xED_CrossesAtCategory->set_visible( m_bCrossingAxisIsCategoryAxis ); |
| 128 |
if (m_bCrossingAxisIsCategoryAxis) |
| 129 |
{ |
| 130 |
for (auto const& cat : m_aCategories) |
| 131 |
m_xED_CrossesAtCategory->append_text(cat); |
| 132 |
} |
| 133 |
|
| 134 |
if( m_xLB_CrossesAt->get_count() > 3 ) |
| 135 |
{ |
| 136 |
if( m_bCrossingAxisIsCategoryAxis ) |
| 137 |
m_xLB_CrossesAt->remove(2); |
| 138 |
else |
| 139 |
m_xLB_CrossesAt->remove(3); |
| 140 |
} |
| 141 |
|
| 142 |
//fill controls |
| 143 |
|
| 144 |
//axis line |
| 145 |
if(SfxInt32Item const * pPositionItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION)) |
| 146 |
{ |
| 147 |
bool bZero = false; |
| 148 |
sal_Int32 nPos = pPositionItem->GetValue(); |
| 149 |
if(nPos==0) |
| 150 |
{ |
| 151 |
//switch to value |
| 152 |
bZero = true; |
| 153 |
nPos = 2; |
| 154 |
} |
| 155 |
else |
| 156 |
nPos--; |
| 157 |
|
| 158 |
if( nPos < m_xLB_CrossesAt->get_count() ) |
| 159 |
m_xLB_CrossesAt->set_active( nPos ); |
| 160 |
CrossesAtSelectHdl( *m_xLB_CrossesAt ); |
| 161 |
|
| 162 |
const SvxDoubleItem* pPosValueItem; |
| 163 |
if( (pPosValueItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION_VALUE)) || bZero ) |
| 164 |
{ |
| 165 |
double fCrossover = 0.0; |
| 166 |
if( !bZero ) |
| 167 |
fCrossover = pPosValueItem->GetValue(); |
| 168 |
if( m_bCrossingAxisIsCategoryAxis ) |
| 169 |
m_xED_CrossesAtCategory->set_active( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) ); |
| 170 |
else |
| 171 |
{ |
| 172 |
Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
| 173 |
rCrossFormatter.SetValue(fCrossover); |
| 174 |
} |
| 175 |
} |
| 176 |
else |
| 177 |
{ |
| 178 |
m_xED_CrossesAtCategory->set_active(-1); |
| 179 |
m_xED_CrossesAt->set_text(u""_ustr); |
| 180 |
} |
| 181 |
} |
| 182 |
else |
| 183 |
{ |
| 184 |
m_xLB_CrossesAt->set_active(-1); |
| 185 |
m_xED_CrossesAt->set_sensitive( false ); |
| 186 |
} |
| 187 |
|
| 188 |
// shifted category position |
| 189 |
const SfxBoolItem* pCatPosItem; |
| 190 |
if (m_bSupportCategoryPositioning && (pCatPosItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION))) |
| 191 |
{ |
| 192 |
if (pCatPosItem->GetValue()) |
| 193 |
m_xRB_Between->set_active(true); |
| 194 |
else |
| 195 |
m_xRB_On->set_active(true); |
| 196 |
} |
| 197 |
else |
| 198 |
m_xFL_Position->hide(); |
| 199 |
|
| 200 |
// Labels |
| 201 |
if( const SfxInt32Item* pLabelPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_LABEL_POSITION, false) ) |
| 202 |
{ |
| 203 |
sal_Int32 nPos = pLabelPosItem->GetValue(); |
| 204 |
if( nPos < m_xLB_PlaceLabels->get_count() ) |
| 205 |
m_xLB_PlaceLabels->set_active( nPos ); |
| 206 |
} |
| 207 |
else |
| 208 |
m_xLB_PlaceLabels->set_active(-1); |
| 209 |
PlaceLabelsSelectHdl( *m_xLB_PlaceLabels ); |
| 210 |
|
| 211 |
// Tick marks |
| 212 |
sal_Int32 nTicks = 0, nMinorTicks = 0; |
| 213 |
if (const SfxInt32Item* pTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_TICKS)) |
| 214 |
nTicks = pTicksItem->GetValue(); |
| 215 |
if (const SfxInt32Item* pHelpTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELPTICKS)) |
| 216 |
nMinorTicks = pHelpTicksItem->GetValue(); |
| 217 |
m_xCB_TicksInner->set_active(AFTicks::checkFlagFor(nTicks, AxisTicksAtr::Inner)); |
| 218 |
m_xCB_TicksOuter->set_active(AFTicks::checkFlagFor(nTicks, AxisTicksAtr::Outer)); |
| 219 |
m_xCB_MinorInner->set_active(AFTicks::checkFlagFor(nMinorTicks, AxisTicksAtr::Inner)); |
| 220 |
m_xCB_MinorOuter->set_active(AFTicks::checkFlagFor(nMinorTicks, AxisTicksAtr::Outer)); |
| 221 |
|
| 222 |
// Tick position |
| 223 |
if( const SfxInt32Item* pMarkPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_MARK_POSITION, false) ) |
| 224 |
{ |
| 225 |
sal_Int32 nPos = pMarkPosItem->GetValue(); |
| 226 |
if( nPos < m_xLB_PlaceTicks->get_count() ) |
| 227 |
m_xLB_PlaceTicks->set_active( nPos ); |
| 228 |
} |
| 229 |
else |
| 230 |
m_xLB_PlaceTicks->set_active(-1); |
| 231 |
|
| 232 |
if( !m_bSupportAxisPositioning ) |
| 233 |
{ |
| 234 |
m_xFL_AxisLine->hide(); |
| 235 |
m_xFL_Labels->hide(); |
| 236 |
m_xBxPlaceTicks->hide(); |
| 237 |
} |
| 238 |
else if( !AxisHelper::isAxisPositioningEnabled() ) |
| 239 |
{ |
| 240 |
m_xFL_AxisLine->set_sensitive(false); |
| 241 |
m_xFL_Labels->set_sensitive(false); |
| 242 |
m_xBxPlaceTicks->set_sensitive(false); |
| 243 |
//todo: maybe set a special help id to all those controls |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
DeactivateRC AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet) |
| 248 |
{ |
| 249 |
if( pItemSet ) |
| 250 |
FillItemSet( pItemSet ); |
| 251 |
|
| 252 |
return DeactivateRC::LeavePage; |
| 253 |
} |
| 254 |
|
| 255 |
void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter ) |
| 256 |
{ |
| 257 |
m_pNumFormatter = pFormatter; |
| 258 |
Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
| 259 |
rCrossFormatter.SetFormatter(m_pNumFormatter); |
| 260 |
rCrossFormatter.UseInputStringForFormatting(); |
| 261 |
|
| 262 |
if( const SfxUInt32Item* pNumFormatItem = GetItemSet().GetItemIfSet(SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT) ) |
| 263 |
{ |
| 264 |
sal_uInt32 nFmt = pNumFormatItem->GetValue(); |
| 265 |
rCrossFormatter.SetFormatKey(nFmt); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis ) |
| 270 |
{ |
| 271 |
m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis; |
| 272 |
} |
| 273 |
|
| 274 |
void AxisPositionsTabPage::SetCategories( const css::uno::Sequence< OUString >& rCategories ) |
| 275 |
{ |
| 276 |
m_aCategories = rCategories; |
| 277 |
} |
| 278 |
|
| 279 |
void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning ) |
| 280 |
{ |
| 281 |
m_bSupportAxisPositioning = bSupportAxisPositioning; |
| 282 |
} |
| 283 |
|
| 284 |
void AxisPositionsTabPage::SupportCategoryPositioning( bool bSupportCategoryPositioning ) |
| 285 |
{ |
| 286 |
m_bSupportCategoryPositioning = bSupportCategoryPositioning; |
| 287 |
} |
| 288 |
|
| 289 |
IMPL_LINK_NOARG(AxisPositionsTabPage, CrossesAtSelectHdl, weld::ComboBox&, void) |
| 290 |
{ |
| 291 |
sal_Int32 nPos = m_xLB_CrossesAt->get_active(); |
| 292 |
m_xED_CrossesAt->set_visible( (nPos==2) && !m_bCrossingAxisIsCategoryAxis ); |
| 293 |
m_xED_CrossesAtCategory->set_visible( (nPos==2) && m_bCrossingAxisIsCategoryAxis ); |
| 294 |
|
| 295 |
if (m_xED_CrossesAt->get_text().isEmpty()) |
| 296 |
m_xED_CrossesAt->GetFormatter().SetValue(0.0); |
| 297 |
if (m_xED_CrossesAtCategory->get_active() == -1 && m_xED_CrossesAtCategory->get_count()) |
| 298 |
m_xED_CrossesAtCategory->set_active(0); |
| 299 |
|
| 300 |
PlaceLabelsSelectHdl(*m_xLB_PlaceLabels); |
| 301 |
} |
| 302 |
|
| 303 |
IMPL_LINK_NOARG(AxisPositionsTabPage, PlaceLabelsSelectHdl, weld::ComboBox&, void) |
| 304 |
{ |
| 305 |
sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active(); |
| 306 |
|
| 307 |
bool bEnableTickmarkPlacement = (nLabelPos>1); |
| 308 |
if( bEnableTickmarkPlacement ) |
| 309 |
{ |
| 310 |
sal_Int32 nAxisPos = m_xLB_CrossesAt->get_active(); |
| 311 |
if( nLabelPos-2 == nAxisPos ) |
| 312 |
bEnableTickmarkPlacement=false; |
| 313 |
} |
| 314 |
m_xBxPlaceTicks->set_sensitive(bEnableTickmarkPlacement); |
| 315 |
} |
| 316 |
|
| 317 |
} //namespace chart |
| 318 |
|
| 319 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |