| 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 <svl/zforlist.hxx> |
| 21 |
|
| 22 |
#include "DataBrowser.hxx" |
| 23 |
#include <DataBrowserModel.hxx> |
| 24 |
#include <strings.hrc> |
| 25 |
#include <DataSeries.hxx> |
| 26 |
#include <DataSeriesHelper.hxx> |
| 27 |
#include <DiagramHelper.hxx> |
| 28 |
#include <CommonConverters.hxx> |
| 29 |
#include <NumberFormatterWrapper.hxx> |
| 30 |
#include <servicenames_charttypes.hxx> |
| 31 |
#include <ResId.hxx> |
| 32 |
#include <bitmaps.hlst> |
| 33 |
#include <helpids.h> |
| 34 |
#include <ChartModel.hxx> |
| 35 |
#include <ChartType.hxx> |
| 36 |
|
| 37 |
#include <vcl/weld.hxx> |
| 38 |
#include <vcl/settings.hxx> |
| 39 |
#include <vcl/svapp.hxx> |
| 40 |
#include <vcl/virdev.hxx> |
| 41 |
#include <o3tl/safeint.hxx> |
| 42 |
#include <osl/diagnose.h> |
| 43 |
#include <svl/numformat.hxx> |
| 44 |
#include <toolkit/helper/vclunohelper.hxx> |
| 45 |
|
| 46 |
#include <com/sun/star/container/XIndexReplace.hpp> |
| 47 |
|
| 48 |
#include <algorithm> |
| 49 |
#include <limits> |
| 50 |
|
| 51 |
|
| 52 |
using namespace ::com::sun::star; |
| 53 |
using ::com::sun::star::uno::Reference; |
| 54 |
|
| 55 |
using namespace ::svt; |
| 56 |
|
| 57 |
namespace |
| 58 |
{ |
| 59 |
/* BrowserMode::COLUMNSELECTION : single cells may be selected rather than only |
| 60 |
entire rows |
| 61 |
BrowserMode::(H|V)LINES : show horizontal or vertical grid-lines |
| 62 |
BrowserMode::AUTO_(H|V)SCROLL : scroll automated horizontally or vertically when |
| 63 |
cursor is moved beyond the edge of the dialog |
| 64 |
BrowserMode::HIDESELECT : Do not mark the current row with selection color |
| 65 |
(usually blue) |
| 66 |
! BrowserMode::HIDECURSOR would prevent flickering in edit fields, but navigating |
| 67 |
with shift up/down, and entering non-editable cells would be problematic, |
| 68 |
e.g. the first cell, or when being in read-only mode |
| 69 |
*/ |
| 70 |
const BrowserMode BrowserStdFlags = BrowserMode::COLUMNSELECTION | |
| 71 |
BrowserMode::HLINES | BrowserMode::VLINES | |
| 72 |
BrowserMode::AUTO_HSCROLL | BrowserMode::AUTO_VSCROLL | |
| 73 |
BrowserMode::HIDESELECT; |
| 74 |
|
| 75 |
sal_Int32 lcl_getColumnInData( sal_uInt16 nCol ) |
| 76 |
{ |
| 77 |
return static_cast< sal_Int32 >( nCol ) - 1; |
| 78 |
} |
| 79 |
|
| 80 |
} // anonymous namespace |
| 81 |
|
| 82 |
namespace chart |
| 83 |
{ |
| 84 |
|
| 85 |
namespace impl |
| 86 |
{ |
| 87 |
|
| 88 |
class SeriesHeaderEdit |
| 89 |
{ |
| 90 |
public: |
| 91 |
explicit SeriesHeaderEdit(std::unique_ptr<weld::Entry> xControl, sal_Int32 nHeader); |
| 92 |
|
| 93 |
void setStartColumn( sal_Int32 nStartColumn ); |
| 94 |
sal_Int32 getStartColumn() const { return m_nStartColumn;} |
| 95 |
void SetShowWarningBox( bool bShowWarning ); |
| 96 |
|
| 97 |
OUString GetText() const { return m_xControl->get_text(); } |
| 98 |
void SetText(const OUString& rText) { m_xControl->set_text(rText); } |
| 99 |
|
| 100 |
bool HasFocus() const { return m_xControl->has_focus(); } |
| 101 |
|
| 102 |
void set_size_request(int nWidth, int nHeight) { m_xControl->set_size_request(nWidth, nHeight); } |
| 103 |
void set_margin_start(int nLeft) { m_xControl->set_margin_start(nLeft); } |
| 104 |
|
| 105 |
void SetModifyHdl(const Link<SeriesHeaderEdit&,void>& rLink) { m_aModifyHdl = rLink; } |
| 106 |
void SetGetFocusHdl(const Link<SeriesHeaderEdit&,void>& rLink) { m_aFocusInHdl = rLink; } |
| 107 |
|
| 108 |
private: |
| 109 |
DECL_LINK(NameEdited, weld::Entry&, void); |
| 110 |
DECL_LINK(NameFocusIn, weld::Widget&, void); |
| 111 |
DECL_LINK(MousePressHdl, const MouseEvent&, bool); |
| 112 |
|
| 113 |
std::unique_ptr<weld::Entry> m_xControl; |
| 114 |
Link<SeriesHeaderEdit&,void> m_aModifyHdl; |
| 115 |
Link<SeriesHeaderEdit&,void> m_aFocusInHdl; |
| 116 |
sal_Int32 m_nStartColumn; |
| 117 |
bool m_bShowWarningBox; |
| 118 |
}; |
| 119 |
|
| 120 |
SeriesHeaderEdit::SeriesHeaderEdit(std::unique_ptr<weld::Entry> xControl, sal_Int32 nHeader) |
| 121 |
: m_xControl(std::move(xControl)) |
| 122 |
, m_nStartColumn(0) |
| 123 |
, m_bShowWarningBox(false) |
| 124 |
{ |
| 125 |
m_xControl->set_help_id(HID_SCH_DATA_SERIES_LABEL); |
| 126 |
m_xControl->connect_changed(LINK(this, SeriesHeaderEdit, NameEdited)); |
| 127 |
m_xControl->connect_focus_in(LINK(this, SeriesHeaderEdit, NameFocusIn)); |
| 128 |
m_xControl->connect_mouse_press(LINK(this, SeriesHeaderEdit, MousePressHdl)); |
| 129 |
|
| 130 |
m_xControl->set_buildable_name(m_xControl->get_buildable_name() + OUString::number(nHeader)); |
| 131 |
} |
| 132 |
|
| 133 |
IMPL_LINK_NOARG(SeriesHeaderEdit, NameEdited, weld::Entry&, void) |
| 134 |
{ |
| 135 |
m_aModifyHdl.Call(*this); |
| 136 |
} |
| 137 |
|
| 138 |
IMPL_LINK_NOARG(SeriesHeaderEdit, NameFocusIn, weld::Widget&, void) |
| 139 |
{ |
| 140 |
m_aFocusInHdl.Call(*this); |
| 141 |
} |
| 142 |
|
| 143 |
void SeriesHeaderEdit::setStartColumn( sal_Int32 nStartColumn ) |
| 144 |
{ |
| 145 |
m_nStartColumn = nStartColumn; |
| 146 |
} |
| 147 |
|
| 148 |
void SeriesHeaderEdit::SetShowWarningBox( bool bShowWarning ) |
| 149 |
{ |
| 150 |
m_bShowWarningBox = bShowWarning; |
| 151 |
} |
| 152 |
|
| 153 |
IMPL_LINK_NOARG(SeriesHeaderEdit, MousePressHdl, const MouseEvent&, bool) |
| 154 |
{ |
| 155 |
if (m_bShowWarningBox) |
| 156 |
{ |
| 157 |
std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xControl.get(), |
| 158 |
VclMessageType::Warning, VclButtonsType::Ok, |
| 159 |
SchResId(STR_INVALID_NUMBER))); |
| 160 |
xWarn->run(); |
| 161 |
} |
| 162 |
|
| 163 |
return false; |
| 164 |
} |
| 165 |
|
| 166 |
class SeriesHeader |
| 167 |
{ |
| 168 |
public: |
| 169 |
explicit SeriesHeader(weld::Box* pParent, weld::Box* pColorParent, sal_Int32 nHeader); |
| 170 |
~SeriesHeader(); |
| 171 |
|
| 172 |
void SetColor( const Color & rCol ); |
| 173 |
void SetPos(); |
| 174 |
void SetWidth( sal_Int32 nWidth ); |
| 175 |
void SetChartType( const rtl::Reference< ::chart::ChartType > & xChartType, |
| 176 |
bool bSwapXAndYAxis ); |
| 177 |
void SetSeriesName( const OUString & rName ); |
| 178 |
void SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ); |
| 179 |
|
| 180 |
void SetPixelWidth( sal_Int32 nWidth ); |
| 181 |
|
| 182 |
sal_Int32 GetStartColumn() const { return m_nStartCol;} |
| 183 |
sal_Int32 GetEndColumn() const { return m_nEndCol;} |
| 184 |
|
| 185 |
static const sal_Int32 nSymbolHeight = 10; |
| 186 |
static const sal_Int32 nSymbolDistance = 2; |
| 187 |
|
| 188 |
static sal_Int32 GetRelativeAppFontXPosForNameField() { return nSymbolHeight + nSymbolDistance; } |
| 189 |
|
| 190 |
void Show(); |
| 191 |
void Hide(); |
| 192 |
|
| 193 |
/** call this before destroying the class. This notifies the listeners to |
| 194 |
changes of the edit field for the series name. |
| 195 |
*/ |
| 196 |
void applyChanges(); |
| 197 |
|
| 198 |
void SetGetFocusHdl(const Link<SeriesHeaderEdit&,void>& rLink); |
| 199 |
|
| 200 |
void SetEditChangedHdl( const Link<SeriesHeaderEdit&,void> & rLink ); |
| 201 |
|
| 202 |
bool HasFocus() const; |
| 203 |
|
| 204 |
private: |
| 205 |
Timer m_aUpdateDataTimer; |
| 206 |
|
| 207 |
std::unique_ptr<weld::Builder> m_xBuilder1; |
| 208 |
std::unique_ptr<weld::Builder> m_xBuilder2; |
| 209 |
|
| 210 |
weld::Box* m_pParent; |
| 211 |
weld::Box* m_pColorParent; |
| 212 |
|
| 213 |
std::unique_ptr<weld::Container> m_xContainer1; |
| 214 |
std::unique_ptr<weld::Container> m_xContainer2; |
| 215 |
std::unique_ptr<weld::Image> m_spSymbol; |
| 216 |
std::unique_ptr<SeriesHeaderEdit> m_spSeriesName; |
| 217 |
std::unique_ptr<weld::Image> m_spColorBar; |
| 218 |
VclPtr< OutputDevice> m_xDevice; |
| 219 |
Link<SeriesHeaderEdit&,void> m_aChangeLink; |
| 220 |
Color m_aColor; |
| 221 |
|
| 222 |
void notifyChanges(); |
| 223 |
DECL_LINK( ImplUpdateDataHdl, Timer*, void ); |
| 224 |
DECL_LINK( SeriesNameEdited, SeriesHeaderEdit&, void ); |
| 225 |
|
| 226 |
static OUString GetChartTypeImage( |
| 227 |
const rtl::Reference< ::chart::ChartType > & xChartType, |
| 228 |
bool bSwapXAndYAxis |
| 229 |
); |
| 230 |
|
| 231 |
sal_Int32 m_nStartCol, m_nEndCol; |
| 232 |
sal_Int32 m_nWidth; |
| 233 |
bool m_bSeriesNameChangePending; |
| 234 |
}; |
| 235 |
|
| 236 |
SeriesHeader::SeriesHeader(weld::Box* pParent, weld::Box* pColorParent, sal_Int32 nHeader) |
| 237 |
: m_aUpdateDataTimer( "SeriesHeader UpdateDataTimer" ) |
| 238 |
, m_xBuilder1(Application::CreateBuilder(pParent, u"modules/schart/ui/columnfragment.ui"_ustr)) |
| 239 |
, m_xBuilder2(Application::CreateBuilder(pColorParent, u"modules/schart/ui/imagefragment.ui"_ustr)) |
| 240 |
, m_pParent(pParent) |
| 241 |
, m_pColorParent(pColorParent) |
| 242 |
, m_xContainer1(m_xBuilder1->weld_container(u"container"_ustr)) |
| 243 |
, m_xContainer2(m_xBuilder2->weld_container(u"container"_ustr)) |
| 244 |
, m_spSymbol(m_xBuilder1->weld_image(u"image"_ustr)) |
| 245 |
, m_spSeriesName(new SeriesHeaderEdit(m_xBuilder1->weld_entry(u"entry"_ustr), nHeader)) |
| 246 |
, m_spColorBar(m_xBuilder2->weld_image(u"image"_ustr)) |
| 247 |
, m_xDevice(Application::GetDefaultDevice()) |
| 248 |
, m_nStartCol( 0 ) |
| 249 |
, m_nEndCol( 0 ) |
| 250 |
, m_nWidth( 42 ) |
| 251 |
, m_bSeriesNameChangePending( false ) |
| 252 |
{ |
| 253 |
m_aUpdateDataTimer.SetInvokeHandler(LINK(this, SeriesHeader, ImplUpdateDataHdl)); |
| 254 |
m_aUpdateDataTimer.SetTimeout(4 * EDIT_UPDATEDATA_TIMEOUT); |
| 255 |
|
| 256 |
m_spSeriesName->SetModifyHdl(LINK(this, SeriesHeader, SeriesNameEdited)); |
| 257 |
Show(); |
| 258 |
} |
| 259 |
|
| 260 |
SeriesHeader::~SeriesHeader() |
| 261 |
{ |
| 262 |
m_aUpdateDataTimer.Stop(); |
| 263 |
m_pParent->move(m_xContainer1.get(), nullptr); |
| 264 |
m_pColorParent->move(m_xContainer2.get(), nullptr); |
| 265 |
} |
| 266 |
|
| 267 |
void SeriesHeader::notifyChanges() |
| 268 |
{ |
| 269 |
m_aChangeLink.Call(*m_spSeriesName); |
| 270 |
m_bSeriesNameChangePending = false; |
| 271 |
} |
| 272 |
|
| 273 |
void SeriesHeader::applyChanges() |
| 274 |
{ |
| 275 |
if( m_bSeriesNameChangePending ) |
| 276 |
{ |
| 277 |
notifyChanges(); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
void SeriesHeader::SetColor( const Color & rCol ) |
| 282 |
{ |
| 283 |
m_aColor = rCol; |
| 284 |
} |
| 285 |
|
| 286 |
void SeriesHeader::SetPos() |
| 287 |
{ |
| 288 |
// chart type symbol |
| 289 |
Size aSize( nSymbolHeight, nSymbolHeight ); |
| 290 |
aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); |
| 291 |
m_spSymbol->set_size_request(aSize.Width(), aSize.Height()); |
| 292 |
|
| 293 |
// series name edit field |
| 294 |
m_spSeriesName->set_margin_start(2); |
| 295 |
|
| 296 |
sal_Int32 nHeightPx = m_xDevice->LogicToPixel(Size(0, 12), MapMode(MapUnit::MapAppFont)).Height(); |
| 297 |
m_spSeriesName->set_size_request(m_nWidth - aSize.Width() - 2, nHeightPx); |
| 298 |
|
| 299 |
// color bar |
| 300 |
nHeightPx = m_xDevice->LogicToPixel(Size(0, 3), MapMode(MapUnit::MapAppFont)).Height(); |
| 301 |
m_spColorBar->set_size_request(m_nWidth, nHeightPx); |
| 302 |
|
| 303 |
ScopedVclPtr<VirtualDevice> xVirDev(m_spColorBar->create_virtual_device()); |
| 304 |
xVirDev->SetOutputSizePixel(Size(m_nWidth, nHeightPx)); |
| 305 |
xVirDev->SetFillColor(m_aColor); |
| 306 |
xVirDev->SetLineColor(m_aColor); |
| 307 |
xVirDev->DrawRect(tools::Rectangle(Point(0, 0), aSize)); |
| 308 |
m_spColorBar->set_image(xVirDev.get()); |
| 309 |
} |
| 310 |
|
| 311 |
void SeriesHeader::SetWidth( sal_Int32 nWidth ) |
| 312 |
{ |
| 313 |
m_nWidth = nWidth; |
| 314 |
SetPos(); |
| 315 |
} |
| 316 |
|
| 317 |
void SeriesHeader::SetPixelWidth( sal_Int32 nWidth ) |
| 318 |
{ |
| 319 |
SetWidth(nWidth); |
| 320 |
} |
| 321 |
|
| 322 |
void SeriesHeader::SetChartType( |
| 323 |
const rtl::Reference< ChartType > & xChartType, |
| 324 |
bool bSwapXAndYAxis |
| 325 |
) |
| 326 |
{ |
| 327 |
m_spSymbol->set_from_icon_name( GetChartTypeImage( xChartType, bSwapXAndYAxis ) ); |
| 328 |
} |
| 329 |
|
| 330 |
void SeriesHeader::SetSeriesName( const OUString & rName ) |
| 331 |
{ |
| 332 |
m_spSeriesName->SetText(rName); |
| 333 |
} |
| 334 |
|
| 335 |
void SeriesHeader::SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ) |
| 336 |
{ |
| 337 |
m_nStartCol = nStartCol; |
| 338 |
m_nEndCol = std::max(nEndCol, nStartCol); |
| 339 |
m_spSeriesName->setStartColumn( nStartCol ); |
| 340 |
} |
| 341 |
|
| 342 |
void SeriesHeader::Show() |
| 343 |
{ |
| 344 |
m_xContainer1->show(); |
| 345 |
m_xContainer2->show(); |
| 346 |
} |
| 347 |
|
| 348 |
void SeriesHeader::Hide() |
| 349 |
{ |
| 350 |
m_xContainer1->hide(); |
| 351 |
m_xContainer2->hide(); |
| 352 |
} |
| 353 |
|
| 354 |
void SeriesHeader::SetEditChangedHdl( const Link<SeriesHeaderEdit&,void> & rLink ) |
| 355 |
{ |
| 356 |
m_aChangeLink = rLink; |
| 357 |
} |
| 358 |
|
| 359 |
IMPL_LINK_NOARG(SeriesHeader, ImplUpdateDataHdl, Timer*, void) |
| 360 |
{ |
| 361 |
notifyChanges(); |
| 362 |
} |
| 363 |
|
| 364 |
IMPL_LINK_NOARG(SeriesHeader, SeriesNameEdited, SeriesHeaderEdit&, void) |
| 365 |
{ |
| 366 |
m_bSeriesNameChangePending = true; |
| 367 |
m_aUpdateDataTimer.Start(); |
| 368 |
} |
| 369 |
|
| 370 |
void SeriesHeader::SetGetFocusHdl( const Link<SeriesHeaderEdit&,void>& rLink ) |
| 371 |
{ |
| 372 |
m_spSeriesName->SetGetFocusHdl( rLink ); |
| 373 |
} |
| 374 |
|
| 375 |
bool SeriesHeader::HasFocus() const |
| 376 |
{ |
| 377 |
return m_spSeriesName->HasFocus(); |
| 378 |
} |
| 379 |
|
| 380 |
OUString SeriesHeader::GetChartTypeImage( |
| 381 |
const rtl::Reference< ChartType > & xChartType, |
| 382 |
bool bSwapXAndYAxis |
| 383 |
) |
| 384 |
{ |
| 385 |
OUString aResult; |
| 386 |
if( !xChartType.is()) |
| 387 |
return aResult; |
| 388 |
OUString aChartTypeName( xChartType->getChartType()); |
| 389 |
|
| 390 |
if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_AREA ) |
| 391 |
{ |
| 392 |
aResult = BMP_TYPE_AREA; |
| 393 |
} |
| 394 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ) |
| 395 |
{ |
| 396 |
if( bSwapXAndYAxis ) |
| 397 |
aResult = BMP_TYPE_BAR; |
| 398 |
else |
| 399 |
aResult = BMP_TYPE_COLUMN; |
| 400 |
} |
| 401 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_LINE ) |
| 402 |
{ |
| 403 |
aResult = BMP_TYPE_LINE; |
| 404 |
} |
| 405 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ) |
| 406 |
{ |
| 407 |
aResult = BMP_TYPE_XY; |
| 408 |
} |
| 409 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_PIE ) |
| 410 |
{ |
| 411 |
aResult = BMP_TYPE_PIE; |
| 412 |
} |
| 413 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_NET |
| 414 |
|| aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ) |
| 415 |
{ |
| 416 |
aResult = BMP_TYPE_NET; |
| 417 |
} |
| 418 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ) |
| 419 |
{ |
| 420 |
// @todo: correct image for candle-stick type |
| 421 |
aResult = BMP_TYPE_STOCK; |
| 422 |
} |
| 423 |
else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE ) |
| 424 |
{ |
| 425 |
aResult = BMP_TYPE_BUBBLE; |
| 426 |
} |
| 427 |
|
| 428 |
return aResult; |
| 429 |
} |
| 430 |
|
| 431 |
} // namespace impl |
| 432 |
|
| 433 |
namespace |
| 434 |
{ |
| 435 |
|
| 436 |
/** returns false, if no header as the focus. |
| 437 |
|
| 438 |
If a header has the focus, true is returned and the index of the header |
| 439 |
with focus is set at pIndex if pOutIndex is not 0. |
| 440 |
*/ |
| 441 |
bool lcl_SeriesHeaderHasFocus( |
| 442 |
const std::vector< std::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader, |
| 443 |
sal_Int32 * pOutIndex = nullptr ) |
| 444 |
{ |
| 445 |
sal_Int32 nIndex = 0; |
| 446 |
for (auto const& elem : rSeriesHeader) |
| 447 |
{ |
| 448 |
if(elem->HasFocus()) |
| 449 |
{ |
| 450 |
if( pOutIndex ) |
| 451 |
*pOutIndex = nIndex; |
| 452 |
return true; |
| 453 |
} |
| 454 |
++nIndex; |
| 455 |
} |
| 456 |
return false; |
| 457 |
} |
| 458 |
|
| 459 |
sal_Int32 lcl_getColumnInDataOrHeader( |
| 460 |
sal_uInt16 nCol, const std::vector< std::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader ) |
| 461 |
{ |
| 462 |
sal_Int32 nColIdx = 0; |
| 463 |
bool bHeaderHasFocus( lcl_SeriesHeaderHasFocus( rSeriesHeader, &nColIdx )); |
| 464 |
|
| 465 |
if( bHeaderHasFocus ) |
| 466 |
nColIdx = lcl_getColumnInData( static_cast< sal_uInt16 >( rSeriesHeader[nColIdx]->GetStartColumn())); |
| 467 |
else |
| 468 |
nColIdx = lcl_getColumnInData( nCol ); |
| 469 |
|
| 470 |
return nColIdx; |
| 471 |
} |
| 472 |
|
| 473 |
} // anonymous namespace |
| 474 |
|
| 475 |
DataBrowser::DataBrowser(const css::uno::Reference<css::awt::XWindow> &rParent, |
| 476 |
weld::Box* pColumns, weld::Box* pColors) : |
| 477 |
::svt::EditBrowseBox(VCLUnoHelper::GetWindow(rParent), |
| 478 |
EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::HANDLE_COLUMN_TEXT, |
| 479 |
WB_BORDER | WB_TABSTOP, BrowserStdFlags ), |
| 480 |
m_nSeekRow( 0 ), |
| 481 |
m_bIsReadOnly( false ), |
| 482 |
m_bDataValid( true ), |
| 483 |
m_aNumberEditField(VclPtr<FormattedControl>::Create(&EditBrowseBox::GetDataWindow(), false)), |
| 484 |
m_aTextEditField(VclPtr<EditControl>::Create(&EditBrowseBox::GetDataWindow())), |
| 485 |
m_pColumnsWin(pColumns), |
| 486 |
m_pColorsWin(pColors), |
| 487 |
m_rNumberEditController( new ::svt::FormattedFieldCellController( m_aNumberEditField.get() )), |
| 488 |
m_rTextEditController( new ::svt::EditCellController( m_aTextEditField.get() )) |
| 489 |
{ |
| 490 |
Formatter& rFormatter = m_aNumberEditField->get_formatter(); |
| 491 |
rFormatter.SetDefaultValue( std::numeric_limits<double>::quiet_NaN() ); |
| 492 |
rFormatter.TreatAsNumber( true ); |
| 493 |
RenewTable(); |
| 494 |
} |
| 495 |
|
| 496 |
DataBrowser::~DataBrowser() |
| 497 |
{ |
| 498 |
disposeOnce(); |
| 499 |
} |
| 500 |
|
| 501 |
void DataBrowser::dispose() |
| 502 |
{ |
| 503 |
m_aSeriesHeaders.clear(); |
| 504 |
m_aNumberEditField.disposeAndClear(); |
| 505 |
m_aTextEditField.disposeAndClear(); |
| 506 |
::svt::EditBrowseBox::dispose(); |
| 507 |
} |
| 508 |
|
| 509 |
bool DataBrowser::MayInsertRow() const |
| 510 |
{ |
| 511 |
return ! IsReadOnly() |
| 512 |
&& ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )); |
| 513 |
} |
| 514 |
|
| 515 |
bool DataBrowser::MayInsertColumn() const |
| 516 |
{ |
| 517 |
return ! IsReadOnly(); |
| 518 |
} |
| 519 |
|
| 520 |
bool DataBrowser::MayDeleteRow() const |
| 521 |
{ |
| 522 |
return ! IsReadOnly() |
| 523 |
&& ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) |
| 524 |
&& ( GetCurRow() >= 0 ) |
| 525 |
&& ( GetRowCount() > 1 ); |
| 526 |
} |
| 527 |
|
| 528 |
bool DataBrowser::MayDeleteColumn() const |
| 529 |
{ |
| 530 |
// if a series header has the focus |
| 531 |
if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) |
| 532 |
return true; |
| 533 |
|
| 534 |
return ! IsReadOnly() |
| 535 |
&& ( GetCurColumnId() > 1 ) |
| 536 |
&& ( ColCount() > 2 ); |
| 537 |
} |
| 538 |
|
| 539 |
bool DataBrowser::MayMoveUpRows() const |
| 540 |
{ |
| 541 |
return ! IsReadOnly() |
| 542 |
&& ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) |
| 543 |
&& ( GetCurRow() > 0 ) |
| 544 |
&& ( GetCurRow() <= GetRowCount() - 1 ); |
| 545 |
} |
| 546 |
|
| 547 |
bool DataBrowser::MayMoveDownRows() const |
| 548 |
{ |
| 549 |
return ! IsReadOnly() |
| 550 |
&& ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) |
| 551 |
&& ( GetCurRow() >= 0 ) |
| 552 |
&& ( GetCurRow() < GetRowCount() - 1 ); |
| 553 |
} |
| 554 |
|
| 555 |
bool DataBrowser::MayMoveLeftColumns() const |
| 556 |
{ |
| 557 |
// if a series header (except the last one) has the focus |
| 558 |
{ |
| 559 |
sal_Int32 nColIndex(0); |
| 560 |
if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex )) |
| 561 |
return (o3tl::make_unsigned( nColIndex ) <= (m_aSeriesHeaders.size() - 1)) && (static_cast< sal_uInt32 >( nColIndex ) != 0); |
| 562 |
} |
| 563 |
|
| 564 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 565 |
return ! IsReadOnly() |
| 566 |
&& ( nColIdx > 1 ) |
| 567 |
&& ( nColIdx <= ColCount() - 2 ) |
| 568 |
&& m_apDataBrowserModel |
| 569 |
&& !m_apDataBrowserModel->isCategoriesColumn( nColIdx ); |
| 570 |
} |
| 571 |
|
| 572 |
bool DataBrowser::MayMoveRightColumns() const |
| 573 |
{ |
| 574 |
// if a series header (except the last one) has the focus |
| 575 |
{ |
| 576 |
sal_Int32 nColIndex(0); |
| 577 |
if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex )) |
| 578 |
return (o3tl::make_unsigned( nColIndex ) < (m_aSeriesHeaders.size() - 1)); |
| 579 |
} |
| 580 |
|
| 581 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 582 |
return ! IsReadOnly() |
| 583 |
&& ( nColIdx > 0 ) |
| 584 |
&& ( nColIdx < ColCount()-2 ) |
| 585 |
&& m_apDataBrowserModel |
| 586 |
&& !m_apDataBrowserModel->isCategoriesColumn( nColIdx ); |
| 587 |
} |
| 588 |
|
| 589 |
void DataBrowser::clearHeaders() |
| 590 |
{ |
| 591 |
for( const auto& spHeader : m_aSeriesHeaders ) |
| 592 |
spHeader->applyChanges(); |
| 593 |
m_aSeriesHeaders.clear(); |
| 594 |
} |
| 595 |
|
| 596 |
void DataBrowser::RenewTable() |
| 597 |
{ |
| 598 |
if (!m_apDataBrowserModel) |
| 599 |
return; |
| 600 |
|
| 601 |
sal_Int32 nOldRow = GetCurRow(); |
| 602 |
sal_uInt16 nOldColId = GetCurColumnId(); |
| 603 |
|
| 604 |
bool bLastUpdateMode = GetUpdateMode(); |
| 605 |
SetUpdateMode( false ); |
| 606 |
|
| 607 |
if( IsModified() ) |
| 608 |
SaveModified(); |
| 609 |
|
| 610 |
DeactivateCell(); |
| 611 |
|
| 612 |
RemoveColumns(); |
| 613 |
RowRemoved( 1, GetRowCount() ); |
| 614 |
|
| 615 |
// for row numbers |
| 616 |
InsertHandleColumn( static_cast< sal_uInt16 >( |
| 617 |
GetDataWindow().LogicToPixel( Size( 42, 0 )).getWidth() )); |
| 618 |
|
| 619 |
OUString aDefaultSeriesName(SchResId(STR_COLUMN_LABEL)); |
| 620 |
replaceParamterInString( aDefaultSeriesName, u"%COLUMNNUMBER", OUString::number( 24 ) ); |
| 621 |
sal_Int32 nColumnWidth = GetDataWindow().GetTextWidth( aDefaultSeriesName ) |
| 622 |
+ GetDataWindow().LogicToPixel(Point(8 + impl::SeriesHeader::GetRelativeAppFontXPosForNameField(), 0), MapMode(MapUnit::MapAppFont)).X(); |
| 623 |
sal_Int32 nColumnCount = m_apDataBrowserModel->getColumnCount(); |
| 624 |
// nRowCount is a member of a base class |
| 625 |
sal_Int32 nRowCountLocal = m_apDataBrowserModel->getMaxRowCount(); |
| 626 |
for( sal_Int32 nColIdx=1; nColIdx<=nColumnCount; ++nColIdx ) |
| 627 |
{ |
| 628 |
InsertDataColumn( static_cast< sal_uInt16 >( nColIdx ), GetColString( nColIdx ), nColumnWidth ); |
| 629 |
} |
| 630 |
|
| 631 |
RowInserted( 1, nRowCountLocal ); |
| 632 |
GoToRow( std::min( nOldRow, GetRowCount() - 1 )); |
| 633 |
GoToColumnId( std::min( nOldColId, static_cast< sal_uInt16 >( ColCount() - 1 ))); |
| 634 |
|
| 635 |
// fill series headers |
| 636 |
clearHeaders(); |
| 637 |
const DataBrowserModel::tDataHeaderVector& aHeaders( m_apDataBrowserModel->getDataHeaders()); |
| 638 |
Link<impl::SeriesHeaderEdit&,void> aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); |
| 639 |
Link<impl::SeriesHeaderEdit&,void> aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); |
| 640 |
|
| 641 |
for (size_t i = 0; i < aHeaders.size(); ++i) |
| 642 |
{ |
| 643 |
auto const& elemHeader = aHeaders[i]; |
| 644 |
auto spHeader = std::make_shared<impl::SeriesHeader>( m_pColumnsWin, m_pColorsWin, i); |
| 645 |
Color nColor; |
| 646 |
// @todo: Set "DraftColor", i.e. interpolated colors for gradients, bitmaps, etc. |
| 647 |
if( elemHeader.m_xDataSeries.is() && |
| 648 |
( elemHeader.m_xDataSeries->getPropertyValue( u"Color"_ustr ) >>= nColor )) |
| 649 |
spHeader->SetColor( nColor ); |
| 650 |
spHeader->SetChartType( elemHeader.m_xChartType, elemHeader.m_bSwapXAndYAxis ); |
| 651 |
spHeader->SetSeriesName( |
| 652 |
elemHeader.m_xDataSeries->getLabelForRole( |
| 653 |
elemHeader.m_xChartType.is() ? |
| 654 |
elemHeader.m_xChartType->getRoleOfSequenceForSeriesLabel() : |
| 655 |
u"values-y"_ustr)); |
| 656 |
// index is 1-based, as 0 is for the column that contains the row-numbers |
| 657 |
spHeader->SetRange( elemHeader.m_nStartColumn + 1, elemHeader.m_nEndColumn + 1 ); |
| 658 |
spHeader->SetGetFocusHdl( aFocusLink ); |
| 659 |
spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); |
| 660 |
m_aSeriesHeaders.push_back(std::move(spHeader)); |
| 661 |
} |
| 662 |
|
| 663 |
ImplAdjustHeaderControls(); |
| 664 |
SetUpdateMode( bLastUpdateMode ); |
| 665 |
ActivateCell(); |
| 666 |
Invalidate(); |
| 667 |
} |
| 668 |
|
| 669 |
const OUString & DataBrowser::GetColString( sal_Int32 nColumnId ) const |
| 670 |
{ |
| 671 |
OSL_ASSERT(m_apDataBrowserModel); |
| 672 |
if( nColumnId > 0 ) |
| 673 |
return m_apDataBrowserModel->getRoleOfColumn( nColumnId - 1 ); |
| 674 |
return EMPTY_OUSTRING; |
| 675 |
} |
| 676 |
|
| 677 |
OUString DataBrowser::GetCellText( sal_Int32 nRow, sal_uInt16 nColumnId ) const |
| 678 |
{ |
| 679 |
OUString aResult; |
| 680 |
|
| 681 |
if( nColumnId == 0 ) |
| 682 |
{ |
| 683 |
aResult = OUString::number(nRow + 1); |
| 684 |
} |
| 685 |
else if( nRow >= 0 && m_apDataBrowserModel) |
| 686 |
{ |
| 687 |
sal_Int32 nColIndex = static_cast< sal_Int32 >( nColumnId ) - 1; |
| 688 |
|
| 689 |
if( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::NUMBER ) |
| 690 |
{ |
| 691 |
double fData( m_apDataBrowserModel->getCellNumber( nColIndex, nRow )); |
| 692 |
|
| 693 |
if( ! std::isnan( fData ) && |
| 694 |
m_spNumberFormatterWrapper ) |
| 695 |
{ |
| 696 |
bool bColorChanged = false; |
| 697 |
Color nLabelColor; |
| 698 |
aResult = m_spNumberFormatterWrapper->getFormattedString( |
| 699 |
GetNumberFormatKey( nColumnId ), |
| 700 |
fData, nLabelColor, bColorChanged ); |
| 701 |
} |
| 702 |
} |
| 703 |
else if( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::TEXTORDATE ) |
| 704 |
{ |
| 705 |
uno::Any aAny = m_apDataBrowserModel->getCellAny( nColIndex, nRow ); |
| 706 |
OUString aText; |
| 707 |
double fDouble=0.0; |
| 708 |
if( aAny>>=aText ) |
| 709 |
aResult = aText; |
| 710 |
else if( aAny>>=fDouble ) |
| 711 |
{ |
| 712 |
if( ! std::isnan( fDouble ) && m_spNumberFormatterWrapper ) |
| 713 |
{ |
| 714 |
// If a numberformat was available here we could directly |
| 715 |
// obtain the corresponding edit format in |
| 716 |
// getDateTimeInputNumberFormat() instead of doing the |
| 717 |
// guess work. |
| 718 |
sal_Int32 nNumberFormat = DiagramHelper::getDateTimeInputNumberFormat( |
| 719 |
m_xChartDoc, fDouble ); |
| 720 |
Color nLabelColor; |
| 721 |
bool bColorChanged = false; |
| 722 |
aResult = m_spNumberFormatterWrapper->getFormattedString( |
| 723 |
nNumberFormat, fDouble, nLabelColor, bColorChanged ); |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
else |
| 728 |
{ |
| 729 |
OSL_ASSERT( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::TEXT ); |
| 730 |
aResult = m_apDataBrowserModel->getCellText( nColIndex, nRow ); |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
return aResult; |
| 735 |
} |
| 736 |
|
| 737 |
double DataBrowser::GetCellNumber( sal_Int32 nRow, sal_uInt16 nColumnId ) const |
| 738 |
{ |
| 739 |
if(( nColumnId >= 1 ) && ( nRow >= 0 ) && m_apDataBrowserModel) |
| 740 |
{ |
| 741 |
return m_apDataBrowserModel->getCellNumber( |
| 742 |
static_cast< sal_Int32 >( nColumnId ) - 1, nRow ); |
| 743 |
} |
| 744 |
|
| 745 |
return std::numeric_limits<double>::quiet_NaN(); |
| 746 |
} |
| 747 |
|
| 748 |
void DataBrowser::Resize() |
| 749 |
{ |
| 750 |
bool bLastUpdateMode = GetUpdateMode(); |
| 751 |
SetUpdateMode( false ); |
| 752 |
|
| 753 |
::svt::EditBrowseBox::Resize(); |
| 754 |
ImplAdjustHeaderControls(); |
| 755 |
SetUpdateMode( bLastUpdateMode ); |
| 756 |
} |
| 757 |
|
| 758 |
void DataBrowser::SetReadOnly( bool bNewState ) |
| 759 |
{ |
| 760 |
if( m_bIsReadOnly != bNewState ) |
| 761 |
{ |
| 762 |
m_bIsReadOnly = bNewState; |
| 763 |
Invalidate(); |
| 764 |
DeactivateCell(); |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
void DataBrowser::CursorMoved() |
| 769 |
{ |
| 770 |
EditBrowseBox::CursorMoved(); |
| 771 |
|
| 772 |
if( GetUpdateMode() ) |
| 773 |
m_aCursorMovedHdlLink.Call( this ); |
| 774 |
} |
| 775 |
|
| 776 |
void DataBrowser::MouseButtonDown( const BrowserMouseEvent& rEvt ) |
| 777 |
{ |
| 778 |
if( !m_bDataValid ) |
| 779 |
ShowWarningBox(); |
| 780 |
else |
| 781 |
EditBrowseBox::MouseButtonDown( rEvt ); |
| 782 |
} |
| 783 |
|
| 784 |
void DataBrowser::ShowWarningBox() |
| 785 |
{ |
| 786 |
std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(), |
| 787 |
VclMessageType::Warning, VclButtonsType::Ok, |
| 788 |
SchResId(STR_INVALID_NUMBER))); |
| 789 |
xWarn->run(); |
| 790 |
} |
| 791 |
|
| 792 |
bool DataBrowser::ShowQueryBox() |
| 793 |
{ |
| 794 |
std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), |
| 795 |
VclMessageType::Question, VclButtonsType::YesNo, |
| 796 |
SchResId(STR_DATA_EDITOR_INCORRECT_INPUT))); |
| 797 |
return xQueryBox->run() == RET_YES; |
| 798 |
} |
| 799 |
|
| 800 |
bool DataBrowser::IsDataValid() const |
| 801 |
{ |
| 802 |
bool bValid = true; |
| 803 |
const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); |
| 804 |
|
| 805 |
if( m_apDataBrowserModel->getCellType( nCol ) == DataBrowserModel::NUMBER ) |
| 806 |
{ |
| 807 |
sal_uInt32 nDummy = 0; |
| 808 |
double fDummy = 0.0; |
| 809 |
OUString aText(m_aNumberEditField->get_widget().get_text()); |
| 810 |
|
| 811 |
if( !aText.isEmpty() && |
| 812 |
m_spNumberFormatterWrapper && |
| 813 |
m_spNumberFormatterWrapper->getSvNumberFormatter() && |
| 814 |
! m_spNumberFormatterWrapper->getSvNumberFormatter()->IsNumberFormat( |
| 815 |
aText, nDummy, fDummy )) |
| 816 |
{ |
| 817 |
bValid = false; |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
return bValid; |
| 822 |
} |
| 823 |
|
| 824 |
void DataBrowser::CellModified() |
| 825 |
{ |
| 826 |
m_bDataValid = IsDataValid(); |
| 827 |
m_aCursorMovedHdlLink.Call( this ); |
| 828 |
} |
| 829 |
|
| 830 |
void DataBrowser::SetDataFromModel( |
| 831 |
const rtl::Reference<::chart::ChartModel> & xChartDoc ) |
| 832 |
{ |
| 833 |
m_xChartDoc = xChartDoc; |
| 834 |
|
| 835 |
m_apDataBrowserModel.reset( new DataBrowserModel( m_xChartDoc )); |
| 836 |
m_spNumberFormatterWrapper = |
| 837 |
std::make_shared<NumberFormatterWrapper>(m_xChartDoc); |
| 838 |
|
| 839 |
Formatter& rFormatter = m_aNumberEditField->get_formatter(); |
| 840 |
rFormatter.SetFormatter( m_spNumberFormatterWrapper->getSvNumberFormatter() ); |
| 841 |
|
| 842 |
RenewTable(); |
| 843 |
|
| 844 |
const sal_Int32 nColCnt = m_apDataBrowserModel->getColumnCount(); |
| 845 |
const sal_Int32 nRowCnt = m_apDataBrowserModel->getMaxRowCount(); |
| 846 |
if( nRowCnt && nColCnt ) |
| 847 |
{ |
| 848 |
GoToRow( 0 ); |
| 849 |
GoToColumnId( 1 ); |
| 850 |
} |
| 851 |
} |
| 852 |
|
| 853 |
void DataBrowser::InsertColumn() |
| 854 |
{ |
| 855 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 856 |
|
| 857 |
if( nColIdx >= 0 && m_apDataBrowserModel) |
| 858 |
{ |
| 859 |
// save changes made to edit-field |
| 860 |
if( IsModified() ) |
| 861 |
SaveModified(); |
| 862 |
|
| 863 |
m_apDataBrowserModel->insertDataSeries( nColIdx ); |
| 864 |
RenewTable(); |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
void DataBrowser::InsertTextColumn() |
| 869 |
{ |
| 870 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 871 |
|
| 872 |
if( nColIdx >= 0 && m_apDataBrowserModel) |
| 873 |
{ |
| 874 |
// save changes made to edit-field |
| 875 |
if( IsModified() ) |
| 876 |
SaveModified(); |
| 877 |
|
| 878 |
m_apDataBrowserModel->insertComplexCategoryLevel( nColIdx ); |
| 879 |
RenewTable(); |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
void DataBrowser::RemoveColumn() |
| 884 |
{ |
| 885 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 886 |
|
| 887 |
if( nColIdx >= 0 && m_apDataBrowserModel) |
| 888 |
{ |
| 889 |
// save changes made to edit-field |
| 890 |
if( IsModified() ) |
| 891 |
SaveModified(); |
| 892 |
|
| 893 |
m_bDataValid = true; |
| 894 |
m_apDataBrowserModel->removeDataSeriesOrComplexCategoryLevel( nColIdx ); |
| 895 |
RenewTable(); |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
void DataBrowser::InsertRow() |
| 900 |
{ |
| 901 |
sal_Int32 nRowIdx = GetCurRow(); |
| 902 |
|
| 903 |
if( nRowIdx >= 0 && m_apDataBrowserModel) |
| 904 |
{ |
| 905 |
// save changes made to edit-field |
| 906 |
if( IsModified() ) |
| 907 |
SaveModified(); |
| 908 |
|
| 909 |
m_apDataBrowserModel->insertDataPointForAllSeries( nRowIdx ); |
| 910 |
RenewTable(); |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
void DataBrowser::RemoveRow() |
| 915 |
{ |
| 916 |
sal_Int32 nRowIdx = GetCurRow(); |
| 917 |
|
| 918 |
if( nRowIdx >= 0 && m_apDataBrowserModel) |
| 919 |
{ |
| 920 |
// save changes made to edit-field |
| 921 |
if( IsModified() ) |
| 922 |
SaveModified(); |
| 923 |
|
| 924 |
m_bDataValid = true; |
| 925 |
m_apDataBrowserModel->removeDataPointForAllSeries( nRowIdx ); |
| 926 |
RenewTable(); |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
void DataBrowser::MoveLeftColumn() |
| 931 |
{ |
| 932 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 933 |
|
| 934 |
if( !(nColIdx > 0 && m_apDataBrowserModel)) |
| 935 |
return; |
| 936 |
|
| 937 |
// save changes made to edit-field |
| 938 |
if( IsModified() ) |
| 939 |
SaveModified(); |
| 940 |
|
| 941 |
m_apDataBrowserModel->swapDataSeries( nColIdx - 1 ); |
| 942 |
|
| 943 |
// keep cursor in swapped column |
| 944 |
if(( 0 < GetCurColumnId() ) && ( GetCurColumnId() <= ColCount() - 1 )) |
| 945 |
{ |
| 946 |
Dispatch(BrowserDispatchId::CURSORLEFT); |
| 947 |
} |
| 948 |
RenewTable(); |
| 949 |
} |
| 950 |
|
| 951 |
void DataBrowser::MoveRightColumn() |
| 952 |
{ |
| 953 |
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); |
| 954 |
|
| 955 |
if( !(nColIdx >= 0 && m_apDataBrowserModel)) |
| 956 |
return; |
| 957 |
|
| 958 |
// save changes made to edit-field |
| 959 |
if( IsModified() ) |
| 960 |
SaveModified(); |
| 961 |
|
| 962 |
m_apDataBrowserModel->swapDataSeries( nColIdx ); |
| 963 |
|
| 964 |
// keep cursor in swapped column |
| 965 |
if( GetCurColumnId() < ColCount() - 1 ) |
| 966 |
{ |
| 967 |
Dispatch(BrowserDispatchId::CURSORRIGHT); |
| 968 |
} |
| 969 |
RenewTable(); |
| 970 |
} |
| 971 |
|
| 972 |
void DataBrowser::MoveUpRow() |
| 973 |
{ |
| 974 |
sal_Int32 nRowIdx = GetCurRow(); |
| 975 |
|
| 976 |
if( !(nRowIdx > 0 && m_apDataBrowserModel)) |
| 977 |
return; |
| 978 |
|
| 979 |
// save changes made to edit-field |
| 980 |
if( IsModified() ) |
| 981 |
SaveModified(); |
| 982 |
|
| 983 |
m_apDataBrowserModel->swapDataPointForAllSeries( nRowIdx - 1 ); |
| 984 |
|
| 985 |
// keep cursor in swapped row |
| 986 |
if(( 0 < GetCurRow() ) && ( GetCurRow() <= GetRowCount() - 1 )) |
| 987 |
{ |
| 988 |
Dispatch(BrowserDispatchId::CURSORUP); |
| 989 |
} |
| 990 |
RenewTable(); |
| 991 |
} |
| 992 |
|
| 993 |
void DataBrowser::MoveDownRow() |
| 994 |
{ |
| 995 |
sal_Int32 nRowIdx = GetCurRow(); |
| 996 |
|
| 997 |
if( !(nRowIdx >= 0 && m_apDataBrowserModel)) |
| 998 |
return; |
| 999 |
|
| 1000 |
// save changes made to edit-field |
| 1001 |
if( IsModified() ) |
| 1002 |
SaveModified(); |
| 1003 |
|
| 1004 |
m_apDataBrowserModel->swapDataPointForAllSeries( nRowIdx ); |
| 1005 |
|
| 1006 |
// keep cursor in swapped row |
| 1007 |
if( GetCurRow() < GetRowCount() - 1 ) |
| 1008 |
{ |
| 1009 |
Dispatch(BrowserDispatchId::CURSORDOWN); |
| 1010 |
} |
| 1011 |
RenewTable(); |
| 1012 |
} |
| 1013 |
|
| 1014 |
void DataBrowser::SetCursorMovedHdl( const Link<DataBrowser*,void>& rLink ) |
| 1015 |
{ |
| 1016 |
m_aCursorMovedHdlLink = rLink; |
| 1017 |
} |
| 1018 |
|
| 1019 |
// implementations for ::svt::EditBrowseBox (pure virtual methods) |
| 1020 |
void DataBrowser::PaintCell( |
| 1021 |
OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColumnId ) const |
| 1022 |
{ |
| 1023 |
Point aPos( rRect.TopLeft()); |
| 1024 |
aPos.AdjustX(1 ); |
| 1025 |
|
| 1026 |
OUString aText = GetCellText( m_nSeekRow, nColumnId ); |
| 1027 |
Size TxtSize( GetDataWindow().GetTextWidth( aText ), GetDataWindow().GetTextHeight()); |
| 1028 |
|
| 1029 |
// clipping |
| 1030 |
if( aPos.X() < rRect.Right() || aPos.X() + TxtSize.Width() > rRect.Right() || |
| 1031 |
aPos.Y() < rRect.Top() || aPos.Y() + TxtSize.Height() > rRect.Bottom()) |
| 1032 |
rDev.SetClipRegion(vcl::Region(rRect)); |
| 1033 |
|
| 1034 |
// allow for a disabled control ... |
| 1035 |
bool bEnabled = IsEnabled(); |
| 1036 |
Color aOriginalColor = rDev.GetTextColor(); |
| 1037 |
if( ! bEnabled ) |
| 1038 |
rDev.SetTextColor( GetSettings().GetStyleSettings().GetDisableColor() ); |
| 1039 |
|
| 1040 |
// draw the text |
| 1041 |
rDev.DrawText( aPos, aText ); |
| 1042 |
|
| 1043 |
// reset the color (if necessary) |
| 1044 |
if( ! bEnabled ) |
| 1045 |
rDev.SetTextColor( aOriginalColor ); |
| 1046 |
|
| 1047 |
if( rDev.IsClipRegion()) |
| 1048 |
rDev.SetClipRegion(); |
| 1049 |
} |
| 1050 |
|
| 1051 |
bool DataBrowser::SeekRow( sal_Int32 nRow ) |
| 1052 |
{ |
| 1053 |
if( ! EditBrowseBox::SeekRow( nRow )) |
| 1054 |
return false; |
| 1055 |
|
| 1056 |
if( nRow < 0 ) |
| 1057 |
m_nSeekRow = - 1; |
| 1058 |
else |
| 1059 |
m_nSeekRow = nRow; |
| 1060 |
|
| 1061 |
return true; |
| 1062 |
} |
| 1063 |
|
| 1064 |
bool DataBrowser::IsTabAllowed( bool bForward ) const |
| 1065 |
{ |
| 1066 |
sal_Int32 nRow = GetCurRow(); |
| 1067 |
sal_Int32 nCol = GetCurColumnId(); |
| 1068 |
|
| 1069 |
// column 0 is header-column |
| 1070 |
sal_Int32 nBadCol = bForward |
| 1071 |
? GetColumnCount() - 1 |
| 1072 |
: 1; |
| 1073 |
sal_Int32 nBadRow = bForward |
| 1074 |
? GetRowCount() - 1 |
| 1075 |
: 0; |
| 1076 |
|
| 1077 |
if( !m_bDataValid ) |
| 1078 |
{ |
| 1079 |
const_cast< DataBrowser* >( this )->ShowWarningBox(); |
| 1080 |
return false; |
| 1081 |
} |
| 1082 |
|
| 1083 |
return ( nRow != nBadRow || |
| 1084 |
nCol != nBadCol ); |
| 1085 |
} |
| 1086 |
|
| 1087 |
::svt::CellController* DataBrowser::GetController( sal_Int32 /*nRow*/, sal_uInt16 nCol ) |
| 1088 |
{ |
| 1089 |
if( m_bIsReadOnly ) |
| 1090 |
return nullptr; |
| 1091 |
|
| 1092 |
if( CellContainsNumbers( nCol )) |
| 1093 |
{ |
| 1094 |
Formatter& rFormatter = m_aNumberEditField->get_formatter(); |
| 1095 |
rFormatter.UseInputStringForFormatting(); |
| 1096 |
rFormatter.SetFormatKey( GetNumberFormatKey( nCol )); |
| 1097 |
return m_rNumberEditController.get(); |
| 1098 |
} |
| 1099 |
|
| 1100 |
return m_rTextEditController.get(); |
| 1101 |
} |
| 1102 |
|
| 1103 |
void DataBrowser::InitController( |
| 1104 |
::svt::CellControllerRef& rController, sal_Int32 nRow, sal_uInt16 nCol ) |
| 1105 |
{ |
| 1106 |
if( rController == m_rTextEditController ) |
| 1107 |
{ |
| 1108 |
OUString aText( GetCellText( nRow, nCol ) ); |
| 1109 |
weld::Entry& rEntry = m_aTextEditField->get_widget(); |
| 1110 |
rEntry.set_text(aText); |
| 1111 |
rEntry.select_region(0, -1); |
| 1112 |
} |
| 1113 |
else if( rController == m_rNumberEditController ) |
| 1114 |
{ |
| 1115 |
// treat invalid and empty text as Nan |
| 1116 |
Formatter& rFormatter = m_aNumberEditField->get_formatter(); |
| 1117 |
rFormatter.EnableNotANumber( true ); |
| 1118 |
if( std::isnan( GetCellNumber( nRow, nCol ))) |
| 1119 |
rFormatter.SetTextValue( OUString()); |
| 1120 |
else |
| 1121 |
rFormatter.SetValue( GetCellNumber( nRow, nCol ) ); |
| 1122 |
weld::Entry& rEntry = m_aNumberEditField->get_widget(); |
| 1123 |
rEntry.select_region(0, -1); |
| 1124 |
} |
| 1125 |
else |
| 1126 |
{ |
| 1127 |
OSL_FAIL( "Invalid Controller" ); |
| 1128 |
} |
| 1129 |
} |
| 1130 |
|
| 1131 |
bool DataBrowser::CellContainsNumbers( sal_uInt16 nCol ) const |
| 1132 |
{ |
| 1133 |
if (!m_apDataBrowserModel) |
| 1134 |
return false; |
| 1135 |
return m_apDataBrowserModel->getCellType( lcl_getColumnInData( nCol )) == DataBrowserModel::NUMBER; |
| 1136 |
} |
| 1137 |
|
| 1138 |
sal_uInt32 DataBrowser::GetNumberFormatKey( sal_uInt16 nCol ) const |
| 1139 |
{ |
| 1140 |
if (!m_apDataBrowserModel) |
| 1141 |
return 0; |
| 1142 |
return m_apDataBrowserModel->getNumberFormatKey( lcl_getColumnInData( nCol ) ); |
| 1143 |
} |
| 1144 |
|
| 1145 |
bool DataBrowser::isDateTimeString( const OUString& aInputString, double& fOutDateTimeValue ) |
| 1146 |
{ |
| 1147 |
sal_uInt32 nNumberFormat=0; |
| 1148 |
SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper ? m_spNumberFormatterWrapper->getSvNumberFormatter() : nullptr; |
| 1149 |
if( !aInputString.isEmpty() && pSvNumberFormatter && pSvNumberFormatter->IsNumberFormat( aInputString, nNumberFormat, fOutDateTimeValue ) ) |
| 1150 |
{ |
| 1151 |
SvNumFormatType nType = pSvNumberFormatter->GetType( nNumberFormat); |
| 1152 |
return (nType & SvNumFormatType::DATE) || (nType & SvNumFormatType::TIME); |
| 1153 |
} |
| 1154 |
return false; |
| 1155 |
} |
| 1156 |
|
| 1157 |
bool DataBrowser::SaveModified() |
| 1158 |
{ |
| 1159 |
if( ! IsModified() ) |
| 1160 |
return true; |
| 1161 |
|
| 1162 |
bool bChangeValid = true; |
| 1163 |
|
| 1164 |
const sal_Int32 nRow = GetCurRow(); |
| 1165 |
const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); |
| 1166 |
|
| 1167 |
OSL_ENSURE( nRow >= 0 || nCol >= 0, "This cell should not be modified!" ); |
| 1168 |
|
| 1169 |
SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper ? m_spNumberFormatterWrapper->getSvNumberFormatter() : nullptr; |
| 1170 |
switch( m_apDataBrowserModel->getCellType( nCol )) |
| 1171 |
{ |
| 1172 |
case DataBrowserModel::NUMBER: |
| 1173 |
{ |
| 1174 |
sal_uInt32 nDummy = 0; |
| 1175 |
double fDummy = 0.0; |
| 1176 |
OUString aText(m_aNumberEditField->get_widget().get_text()); |
| 1177 |
// an empty string is valid, if no numberformatter exists, all |
| 1178 |
// values are treated as valid |
| 1179 |
if( !aText.isEmpty() && pSvNumberFormatter && |
| 1180 |
! pSvNumberFormatter->IsNumberFormat( aText, nDummy, fDummy ) ) |
| 1181 |
{ |
| 1182 |
bChangeValid = false; |
| 1183 |
} |
| 1184 |
else |
| 1185 |
{ |
| 1186 |
Formatter& rFormatter = m_aNumberEditField->get_formatter(); |
| 1187 |
double fData = rFormatter.GetValue(); |
| 1188 |
bChangeValid = m_apDataBrowserModel->setCellNumber( nCol, nRow, fData ); |
| 1189 |
} |
| 1190 |
} |
| 1191 |
break; |
| 1192 |
case DataBrowserModel::TEXTORDATE: |
| 1193 |
{ |
| 1194 |
weld::Entry& rEntry = m_aTextEditField->get_widget(); |
| 1195 |
OUString aText(rEntry.get_text()); |
| 1196 |
double fValue = 0.0; |
| 1197 |
bChangeValid = false; |
| 1198 |
if( isDateTimeString( aText, fValue ) ) |
| 1199 |
bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::Any( fValue ) ); |
| 1200 |
if(!bChangeValid) |
| 1201 |
bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::Any( aText ) ); |
| 1202 |
} |
| 1203 |
break; |
| 1204 |
case DataBrowserModel::TEXT: |
| 1205 |
{ |
| 1206 |
weld::Entry& rEntry = m_aTextEditField->get_widget(); |
| 1207 |
OUString aText(rEntry.get_text()); |
| 1208 |
bChangeValid = m_apDataBrowserModel->setCellText( nCol, nRow, aText ); |
| 1209 |
} |
| 1210 |
break; |
| 1211 |
} |
| 1212 |
|
| 1213 |
// the first valid change changes this to true |
| 1214 |
if( bChangeValid ) |
| 1215 |
{ |
| 1216 |
RowModified( GetCurRow(), GetCurColumnId()); |
| 1217 |
::svt::CellController* pCtrl = GetController( GetCurRow(), GetCurColumnId()); |
| 1218 |
if( pCtrl ) |
| 1219 |
pCtrl->SaveValue(); |
| 1220 |
} |
| 1221 |
|
| 1222 |
return bChangeValid; |
| 1223 |
} |
| 1224 |
|
| 1225 |
bool DataBrowser::EndEditing() |
| 1226 |
{ |
| 1227 |
SaveModified(); |
| 1228 |
|
| 1229 |
// apply changes made to series headers |
| 1230 |
for( const auto& spHeader : m_aSeriesHeaders ) |
| 1231 |
spHeader->applyChanges(); |
| 1232 |
|
| 1233 |
if( m_bDataValid ) |
| 1234 |
return true; |
| 1235 |
else |
| 1236 |
return ShowQueryBox(); |
| 1237 |
} |
| 1238 |
|
| 1239 |
void DataBrowser::ColumnResized( sal_uInt16 nColId ) |
| 1240 |
{ |
| 1241 |
bool bLastUpdateMode = GetUpdateMode(); |
| 1242 |
SetUpdateMode( false ); |
| 1243 |
|
| 1244 |
EditBrowseBox::ColumnResized( nColId ); |
| 1245 |
ImplAdjustHeaderControls(); |
| 1246 |
SetUpdateMode( bLastUpdateMode ); |
| 1247 |
} |
| 1248 |
|
| 1249 |
void DataBrowser::EndScroll() |
| 1250 |
{ |
| 1251 |
bool bLastUpdateMode = GetUpdateMode(); |
| 1252 |
SetUpdateMode( false ); |
| 1253 |
|
| 1254 |
EditBrowseBox::EndScroll(); |
| 1255 |
RenewSeriesHeaders(); |
| 1256 |
|
| 1257 |
SetUpdateMode( bLastUpdateMode ); |
| 1258 |
} |
| 1259 |
|
| 1260 |
void DataBrowser::RenewSeriesHeaders() |
| 1261 |
{ |
| 1262 |
clearHeaders(); |
| 1263 |
DataBrowserModel::tDataHeaderVector aHeaders( m_apDataBrowserModel->getDataHeaders()); |
| 1264 |
Link<impl::SeriesHeaderEdit&,void> aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); |
| 1265 |
Link<impl::SeriesHeaderEdit&,void> aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); |
| 1266 |
|
| 1267 |
|
| 1268 |
for (size_t i = 0; i < aHeaders.size(); ++i) |
| 1269 |
{ |
| 1270 |
auto const& elemHeader = aHeaders[i]; |
| 1271 |
auto spHeader = std::make_shared<impl::SeriesHeader>( m_pColumnsWin, m_pColorsWin, i ); |
| 1272 |
Color nColor; |
| 1273 |
if( elemHeader.m_xDataSeries.is() && |
| 1274 |
( elemHeader.m_xDataSeries->getPropertyValue( u"Color"_ustr ) >>= nColor )) |
| 1275 |
spHeader->SetColor( nColor ); |
| 1276 |
spHeader->SetChartType( elemHeader.m_xChartType, elemHeader.m_bSwapXAndYAxis ); |
| 1277 |
spHeader->SetSeriesName( |
| 1278 |
elemHeader.m_xDataSeries->getLabelForRole( |
| 1279 |
elemHeader.m_xChartType.is() ? |
| 1280 |
elemHeader.m_xChartType->getRoleOfSequenceForSeriesLabel() : |
| 1281 |
u"values-y"_ustr)); |
| 1282 |
spHeader->SetRange( elemHeader.m_nStartColumn + 1, elemHeader.m_nEndColumn + 1 ); |
| 1283 |
spHeader->SetGetFocusHdl( aFocusLink ); |
| 1284 |
spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); |
| 1285 |
m_aSeriesHeaders.push_back(std::move(spHeader)); |
| 1286 |
} |
| 1287 |
|
| 1288 |
ImplAdjustHeaderControls(); |
| 1289 |
} |
| 1290 |
|
| 1291 |
void DataBrowser::ImplAdjustHeaderControls() |
| 1292 |
{ |
| 1293 |
sal_uInt16 nColCount = GetColumnCount(); |
| 1294 |
sal_uInt32 nCurrentPos = GetPosPixel().getX(); |
| 1295 |
sal_uInt32 nMaxPos = nCurrentPos + GetOutputSizePixel().getWidth(); |
| 1296 |
sal_uInt32 nStartPos = nCurrentPos; |
| 1297 |
|
| 1298 |
// width of header column |
| 1299 |
nCurrentPos += GetColumnWidth( 0 ); |
| 1300 |
|
| 1301 |
weld::Container* pWin = m_pColumnsWin; |
| 1302 |
weld::Container* pColorWin = m_pColorsWin; |
| 1303 |
pWin->set_margin_start(nCurrentPos); |
| 1304 |
pColorWin->set_margin_start(nCurrentPos); |
| 1305 |
|
| 1306 |
tSeriesHeaderContainer::iterator aIt( m_aSeriesHeaders.begin()); |
| 1307 |
sal_uInt16 i = GetFirstVisibleColNumber(); |
| 1308 |
while( (aIt != m_aSeriesHeaders.end()) && ((*aIt)->GetStartColumn() < i) ) |
| 1309 |
{ |
| 1310 |
(*aIt)->Hide(); |
| 1311 |
++aIt; |
| 1312 |
} |
| 1313 |
for( ; i < nColCount && aIt != m_aSeriesHeaders.end(); ++i ) |
| 1314 |
{ |
| 1315 |
if( (*aIt)->GetStartColumn() == i ) |
| 1316 |
nStartPos = nCurrentPos; |
| 1317 |
|
| 1318 |
nCurrentPos += (GetColumnWidth( i )); |
| 1319 |
|
| 1320 |
if( (*aIt)->GetEndColumn() == i ) |
| 1321 |
{ |
| 1322 |
if( nStartPos < nMaxPos ) |
| 1323 |
{ |
| 1324 |
(*aIt)->SetPixelWidth( nCurrentPos - nStartPos ); |
| 1325 |
(*aIt)->Show(); |
| 1326 |
|
| 1327 |
if (pWin) |
| 1328 |
{ |
| 1329 |
pWin->set_margin_start(nStartPos); |
| 1330 |
pColorWin->set_margin_start(nStartPos); |
| 1331 |
pWin = pColorWin = nullptr; |
| 1332 |
} |
| 1333 |
|
| 1334 |
} |
| 1335 |
else |
| 1336 |
(*aIt)->Hide(); |
| 1337 |
++aIt; |
| 1338 |
} |
| 1339 |
} |
| 1340 |
} |
| 1341 |
|
| 1342 |
IMPL_LINK( DataBrowser, SeriesHeaderGotFocus, impl::SeriesHeaderEdit&, rEdit, void ) |
| 1343 |
{ |
| 1344 |
rEdit.SetShowWarningBox( !m_bDataValid ); |
| 1345 |
|
| 1346 |
if( !m_bDataValid ) |
| 1347 |
GoToCell( 0, 0 ); |
| 1348 |
else |
| 1349 |
{ |
| 1350 |
MakeFieldVisible( GetCurRow(), static_cast< sal_uInt16 >( rEdit.getStartColumn()) ); |
| 1351 |
ActivateCell(); |
| 1352 |
m_aCursorMovedHdlLink.Call( this ); |
| 1353 |
} |
| 1354 |
} |
| 1355 |
|
| 1356 |
IMPL_LINK( DataBrowser, SeriesHeaderChanged, impl::SeriesHeaderEdit&, rEdit, void ) |
| 1357 |
{ |
| 1358 |
rtl::Reference< DataSeries > xSeries = |
| 1359 |
m_apDataBrowserModel->getDataSeriesByColumn( rEdit.getStartColumn() - 1 ); |
| 1360 |
if( !xSeries.is()) |
| 1361 |
return; |
| 1362 |
|
| 1363 |
rtl::Reference< ChartType > xChartType( |
| 1364 |
m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType ); |
| 1365 |
if( xChartType.is()) |
| 1366 |
{ |
| 1367 |
uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSeq = |
| 1368 |
DataSeriesHelper::getDataSequenceByRole( xSeries, xChartType->getRoleOfSequenceForSeriesLabel()); |
| 1369 |
if( xLabeledSeq.is()) |
| 1370 |
{ |
| 1371 |
Reference< container::XIndexReplace > xIndexReplace( xLabeledSeq->getLabel(), uno::UNO_QUERY ); |
| 1372 |
if( xIndexReplace.is()) |
| 1373 |
xIndexReplace->replaceByIndex( |
| 1374 |
0, uno::Any( rEdit.GetText())); |
| 1375 |
} |
| 1376 |
} |
| 1377 |
} |
| 1378 |
|
| 1379 |
} // namespace chart |
| 1380 |
|
| 1381 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |