Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/chart2/source/controller/main/ChartController_Tools.cxx
Line
Count
Source (jump to first uncovered line)
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 <ChartController.hxx>
21
#include <ChartWindow.hxx>
22
#include <ChartModel.hxx>
23
#include <ChartType.hxx>
24
#include <TitleHelper.hxx>
25
#include <DataSeries.hxx>
26
#include <DataSeriesHelper.hxx>
27
#include "UndoGuard.hxx"
28
#include <ControllerLockGuard.hxx>
29
#include <ResId.hxx>
30
#include <strings.hrc>
31
#include <ObjectIdentifier.hxx>
32
#include <ReferenceSizeProvider.hxx>
33
#include <chartview/DrawModelWrapper.hxx>
34
#include "ChartTransferable.hxx"
35
#include <DrawViewWrapper.hxx>
36
#include <Legend.hxx>
37
#include <LegendHelper.hxx>
38
#include <Axis.hxx>
39
#include <AxisHelper.hxx>
40
#include <RegressionCurveModel.hxx>
41
#include <RegressionCurveHelper.hxx>
42
#include "ShapeController.hxx"
43
#include <DiagramHelper.hxx>
44
#include <Diagram.hxx>
45
#include <ObjectNameProvider.hxx>
46
#include <unonames.hxx>
47
48
#include <com/sun/star/awt/FontWeight.hpp>
49
#include <com/sun/star/awt/Gradient.hpp>
50
#include <com/sun/star/chart2/DataPointLabel.hpp>
51
#include <com/sun/star/graphic/XGraphic.hpp>
52
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
53
#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
54
#include <com/sun/star/chart/ErrorBarStyle.hpp>
55
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
56
57
#include <docmodel/uno/UnoGradientTools.hxx>
58
#include <editeng/editview.hxx>
59
#include <editeng/outliner.hxx>
60
#include <svx/ActionDescriptionProvider.hxx>
61
#include <vcl/transfer.hxx>
62
#include <sot/storage.hxx>
63
#include <vcl/graph.hxx>
64
#include <vcl/TypeSerializer.hxx>
65
#include <svx/unomodel.hxx>
66
#include <svx/svdmodel.hxx>
67
#include <unotools/streamwrap.hxx>
68
#include <vcl/svapp.hxx>
69
#include <svx/dialmgr.hxx>
70
#include <svx/strings.hrc>
71
#include <svx/svditer.hxx>
72
#include <svx/svdpage.hxx>
73
#include <svx/svdundo.hxx>
74
#include <svx/unoapi.hxx>
75
#include <svx/unopage.hxx>
76
#include <svx/unoshape.hxx>
77
#include <PropertyHelper.hxx>
78
79
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
80
#include <tools/debug.hxx>
81
#include <comphelper/diagnose_ex.hxx>
82
#include <tools/UnitConversion.hxx>
83
84
#include <memory>
85
86
using namespace ::com::sun::star;
87
88
using ::com::sun::star::uno::Reference;
89
using ::com::sun::star::uno::Sequence;
90
91
namespace chart
92
{
93
94
namespace
95
{
96
97
bool lcl_deleteDataSeries(
98
    std::u16string_view rCID,
99
    const rtl::Reference<::chart::ChartModel> & xModel,
100
    const Reference< document::XUndoManager > & xUndoManager )
101
0
{
102
0
    bool bResult = false;
103
0
    rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rCID, xModel );
104
0
    if( xSeries.is() && xModel.is())
105
0
    {
106
0
        rtl::Reference< ::chart::ChartType > xChartType =
107
0
            DataSeriesHelper::getChartTypeOfSeries( xSeries, xModel->getFirstChartDiagram());
108
0
        if( xChartType.is())
109
0
        {
110
0
            UndoGuard aUndoGuard(
111
0
                ActionDescriptionProvider::createDescription(
112
0
                    ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_DATASERIES )),
113
0
                xUndoManager );
114
115
0
            rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
116
0
            rtl::Reference< Axis > xAxis = xDiagram->getAttachedAxis( xSeries );
117
118
0
            xChartType->deleteSeries( xSeries );
119
120
0
            AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram );
121
122
0
            bResult = true;
123
0
            aUndoGuard.commit();
124
0
        }
125
0
    }
126
0
    return bResult;
127
0
}
128
129
bool lcl_deleteDataCurve(
130
    std::u16string_view rCID,
131
    const rtl::Reference<::chart::ChartModel> & xModel,
132
    const Reference< document::XUndoManager > & xUndoManager )
133
0
{
134
0
    bool bResult = false;
135
136
0
    uno::Reference< beans::XPropertySet > xProperties(
137
0
        ObjectIdentifier::getObjectPropertySet( rCID, xModel));
138
139
0
    uno::Reference< chart2::XRegressionCurve > xRegressionCurve( xProperties, uno::UNO_QUERY );
140
141
0
    if( xRegressionCurve.is())
142
0
    {
143
0
        uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
144
0
            ObjectIdentifier::getObjectPropertySet(
145
0
                ObjectIdentifier::getFullParentParticle( rCID ), xModel), uno::UNO_QUERY );
146
147
0
        if( xRegressionCurveContainer.is())
148
0
        {
149
0
            UndoGuard aUndoGuard(
150
0
                ActionDescriptionProvider::createDescription(
151
0
                    ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
152
0
                xUndoManager );
153
154
0
            xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
155
156
0
            bResult = true;
157
0
            aUndoGuard.commit();
158
0
        }
159
0
    }
160
0
    return bResult;
161
0
}
162
163
bool lcl_arePropertiesSame(const std::vector<Reference<beans::XPropertySet>>& xProperties,
164
                           OUString& aPropName)
165
0
{
166
0
    if (xProperties.size() == 1)
167
0
        return true;
168
0
    if (xProperties.size() < 1)
169
0
        return false;
170
171
0
    uno::Any aValue = xProperties[0]->getPropertyValue(aPropName);
172
0
    for (std::size_t i = 1; i < xProperties.size(); i++)
173
0
    {
174
0
        if (aValue != xProperties[i]->getPropertyValue(aPropName))
175
0
            return false;
176
0
    }
177
0
    return true;
178
0
}
179
180
} // anonymous namespace
181
182
ReferenceSizeProvider ChartController::impl_createReferenceSizeProvider()
183
0
{
184
0
    awt::Size aPageSize( getChartModel()->getPageSize() );
185
186
0
    return ReferenceSizeProvider(aPageSize, getChartModel());
187
0
}
188
189
void ChartController::impl_adaptDataSeriesAutoResize()
190
0
{
191
0
    impl_createReferenceSizeProvider().setValuesAtAllDataSeries();
192
0
}
193
194
void ChartController::executeDispatch_NewArrangement()
195
0
{
196
    // remove manual positions at titles, legend and the diagram, remove manual
197
    // size at the diagram
198
199
0
    try
200
0
    {
201
0
        rtl::Reference<::chart::ChartModel> xModel( getChartModel() );
202
0
        rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
203
0
        if( xDiagram.is())
204
0
        {
205
0
            UndoGuard aUndoGuard(
206
0
                SchResId( STR_ACTION_REARRANGE_CHART ),
207
0
                m_xUndoManager );
208
0
            ControllerLockGuardUNO aCtlLockGuard( xModel );
209
210
            // diagram
211
0
            xDiagram->setPropertyToDefault( u"RelativeSize"_ustr);
212
0
            xDiagram->setPropertyToDefault( u"RelativePosition"_ustr);
213
0
            xDiagram->setPropertyToDefault( u"PosSizeExcludeAxes"_ustr);
214
215
            // 3d rotation
216
0
            xDiagram->set3DSettingsToDefault();
217
218
            // legend
219
0
            rtl::Reference< Legend > xLegend = xDiagram->getLegend2();
220
0
            if( xLegend.is())
221
0
            {
222
0
                xLegend->setPropertyToDefault( u"RelativePosition"_ustr);
223
0
                xLegend->setPropertyToDefault( u"RelativeSize"_ustr);
224
0
                xLegend->setPropertyToDefault( u"AnchorPosition"_ustr);
225
0
            }
226
227
            // titles
228
0
            for( sal_Int32 eType = TitleHelper::TITLE_BEGIN;
229
0
                 eType < TitleHelper::NORMAL_TITLE_END;
230
0
                 ++eType )
231
0
            {
232
0
                rtl::Reference< Title > xTitleState =
233
0
                    TitleHelper::getTitle(
234
0
                        static_cast< TitleHelper::eTitleType >( eType ), xModel );
235
0
                if( xTitleState.is())
236
0
                    xTitleState->setPropertyToDefault( u"RelativePosition"_ustr);
237
0
            }
238
239
            // regression curve equations
240
0
            std::vector< rtl::Reference< RegressionCurveModel > > aRegressionCurves =
241
0
                xDiagram->getAllRegressionCurvesNotMeanValueLine();
242
243
            // reset equation position
244
0
            for( const auto& xCurve : aRegressionCurves )
245
0
                RegressionCurveHelper::resetEquationPosition( xCurve );
246
247
0
            aUndoGuard.commit();
248
0
        }
249
0
    }
250
0
    catch( const uno::RuntimeException & )
251
0
    {
252
0
        DBG_UNHANDLED_EXCEPTION("chart2");
253
0
    }
254
0
}
255
256
void ChartController::executeDispatch_ScaleText()
257
0
{
258
0
    SolarMutexGuard aSolarGuard;
259
0
    UndoGuard aUndoGuard(
260
0
        SchResId( STR_ACTION_SCALE_TEXT ),
261
0
        m_xUndoManager );
262
0
    ControllerLockGuardUNO aCtlLockGuard( getChartModel() );
263
264
0
    impl_createReferenceSizeProvider().toggleAutoResizeState();
265
266
0
    aUndoGuard.commit();
267
0
}
268
269
void ChartController::executeDispatch_FontBold(
270
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
271
0
{
272
0
    OUString aPropName = u"CharWeight"_ustr;
273
0
    float nFontWeight = awt::FontWeight::NORMAL;
274
0
    if (lcl_arePropertiesSame(xProperties, aPropName))
275
0
    {
276
0
        xProperties[0]->getPropertyValue(aPropName) >>= nFontWeight;
277
0
    }
278
0
    nFontWeight = (nFontWeight == awt::FontWeight::NORMAL) ? awt::FontWeight::BOLD
279
0
                                                           : awt::FontWeight::NORMAL;
280
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
281
0
        xProperties[i]->setPropertyValue(aPropName, uno::Any(nFontWeight));
282
0
}
283
284
void ChartController::executeDispatch_FontName(
285
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties,
286
    const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
287
0
{
288
    // the sent font may have a lot of properties that we could set.
289
    // but now we set only this
290
0
    awt::FontDescriptor aFont;
291
0
    rArgs[0].Value >>= aFont;
292
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
293
0
        xProperties[i]->setPropertyValue(u"CharFontName"_ustr, css::uno::Any(aFont.Name));
294
0
}
295
296
void ChartController::executeDispatch_FontHeight(
297
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties,
298
    const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
299
0
{
300
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
301
0
        xProperties[i]->setPropertyValue(u"CharHeight"_ustr, rArgs[0].Value);
302
0
}
303
304
void ChartController::executeDispatch_FontItalic(
305
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
306
0
{
307
0
    OUString aPropName = u"CharPosture"_ustr;
308
0
    awt::FontSlant nFontItalic = awt::FontSlant::FontSlant_NONE;
309
0
    if (lcl_arePropertiesSame(xProperties, aPropName))
310
0
    {
311
0
        xProperties[0]->getPropertyValue(aPropName) >>= nFontItalic;
312
0
    }
313
0
    nFontItalic = (nFontItalic == awt::FontSlant::FontSlant_NONE ? awt::FontSlant::FontSlant_ITALIC
314
0
                                                                 : awt::FontSlant::FontSlant_NONE);
315
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
316
0
        xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontItalic));
317
0
}
318
319
void ChartController::executeDispatch_FontUnderline(
320
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties,
321
    const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
322
0
{
323
0
    OUString aPropName = u"CharUnderline"_ustr;
324
0
    sal_Int16 nFontUnderline = 0;
325
0
    sal_Int32 nFontUnderline32 = 0;
326
0
    if (!(rArgs[0].Value >>= nFontUnderline) && (rArgs[0].Value >>= nFontUnderline32))
327
0
    {
328
0
        nFontUnderline = nFontUnderline32;
329
0
    }
330
0
    else
331
0
    {
332
0
        if (lcl_arePropertiesSame(xProperties, aPropName))
333
0
        {
334
0
            xProperties[0]->getPropertyValue(aPropName) >>= nFontUnderline;
335
0
        }
336
0
        nFontUnderline = (nFontUnderline == 0 ? 1 : 0);
337
0
    }
338
339
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
340
0
        xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontUnderline));
341
0
}
342
343
void ChartController::executeDispatch_FontStrikeout(
344
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
345
0
{
346
0
    OUString aPropName = u"CharStrikeout"_ustr;
347
0
    sal_Int16 nFontStrikeout = 0;
348
0
    if (lcl_arePropertiesSame(xProperties, aPropName))
349
0
    {
350
0
        xProperties[0]->getPropertyValue(aPropName) >>= nFontStrikeout;
351
0
    }
352
0
    nFontStrikeout = (nFontStrikeout == 0 ? 1 : 0);
353
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
354
0
        xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontStrikeout));
355
0
}
356
357
void ChartController::executeDispatch_FontShadowed(
358
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
359
0
{
360
0
    OUString aPropName = u"CharShadowed"_ustr;
361
0
    bool bFontShadowed = false;
362
0
    if (lcl_arePropertiesSame(xProperties, aPropName))
363
0
    {
364
0
        xProperties[0]->getPropertyValue(aPropName) >>= bFontShadowed;
365
0
    }
366
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
367
0
        xProperties[i]->setPropertyValue(u"CharShadowed"_ustr, css::uno::Any(!bFontShadowed));
368
0
}
369
370
void ChartController::executeDispatch_FontColor(
371
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties,
372
    const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
373
0
{
374
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
375
0
        xProperties[i]->setPropertyValue(u"CharColor"_ustr, rArgs[0].Value);
376
0
}
377
378
void ChartController::executeDispatch_FontGrow(
379
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
380
0
{
381
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
382
0
    {
383
0
        float nFontHeight = 0;
384
0
        xProperties[i]->getPropertyValue(u"CharHeight"_ustr) >>= nFontHeight;
385
0
        if (nFontHeight > 0)
386
0
        {
387
0
            nFontHeight = ceil(nFontHeight); //round
388
0
            nFontHeight += 1;
389
0
            if (nFontHeight > 999)
390
0
                nFontHeight = 999;
391
0
            xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(nFontHeight));
392
0
        }
393
0
    }
394
0
}
395
396
void ChartController::executeDispatch_FontShrink(
397
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
398
0
{
399
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
400
0
    {
401
0
        float nFontHeight = 0;
402
0
        xProperties[i]->getPropertyValue(u"CharHeight"_ustr) >>= nFontHeight;
403
0
        if (nFontHeight > 0)
404
0
        {
405
0
            if (nFontHeight - ceil(nFontHeight) >= 0.4)
406
0
                nFontHeight = ceil(nFontHeight); //round
407
0
            else
408
0
            {
409
0
                nFontHeight -= 1;
410
0
                if (nFontHeight < 2)
411
0
                    nFontHeight = 2;
412
0
            }
413
0
            xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(nFontHeight));
414
0
        }
415
0
    }
416
0
}
417
418
void ChartController::executeDispatch_FontReset(
419
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
420
0
{
421
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
422
0
    {
423
0
        xProperties[i]->setPropertyValue(u"CharFontName"_ustr,
424
0
                                         css::uno::Any(OUString("Liberation Sans")));
425
0
        xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(float(13)));
426
0
        xProperties[i]->setPropertyValue(u"CharWeight"_ustr, uno::Any(float(100)));
427
0
        xProperties[i]->setPropertyValue(u"CharPosture"_ustr,
428
0
                                         css::uno::Any(awt::FontSlant::FontSlant_NONE));
429
0
        xProperties[i]->setPropertyValue(u"CharUnderline"_ustr, css::uno::Any(sal_Int16(0)));
430
0
        xProperties[i]->setPropertyValue(u"CharStrikeout"_ustr, css::uno::Any(sal_Int16(0)));
431
0
        xProperties[i]->setPropertyValue(u"CharShadowed"_ustr, css::uno::Any(false));
432
0
        xProperties[i]->setPropertyValue(u"CharColor"_ustr, css::uno::Any(Color(0)));
433
434
0
        xProperties[i]->setPropertyValue(u"CharKerning"_ustr, css::uno::Any(sal_Int16(0)));
435
0
        xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0)));
436
0
        xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr,
437
0
                                         css::uno::Any(sal_Int8(100)));
438
0
    }
439
0
}
440
441
void ChartController::executeDispatch_FontSpacing(
442
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties,
443
    const css::uno::Sequence<css::beans::PropertyValue>& rArgs)
444
0
{
445
0
    sal_Int16 nKerning = 0;
446
0
    rArgs[0].Value >>= nKerning;
447
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
448
0
        xProperties[i]->setPropertyValue(u"CharKerning"_ustr, css::uno::Any(nKerning));
449
0
}
450
451
void ChartController::executeDispatch_FontSuperScript(
452
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
453
0
{
454
0
    sal_Int16 nCharEscapement = 0;
455
0
    xProperties[0]->getPropertyValue(u"CharEscapement"_ustr) >>= nCharEscapement;
456
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
457
0
    {
458
0
        if (nCharEscapement > 0)
459
0
        {
460
0
            xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0)));
461
0
            xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr,
462
0
                                             css::uno::Any(sal_Int8(100)));
463
0
        }
464
0
        else
465
0
        {
466
0
            xProperties[i]->setPropertyValue(u"CharEscapement"_ustr,
467
0
                                             css::uno::Any(sal_Int16(14000)));
468
0
            xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr,
469
0
                                             css::uno::Any(sal_Int8(58)));
470
0
        }
471
0
    }
472
0
}
473
474
void ChartController::executeDispatch_FontSubScript(
475
    const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties)
476
0
{
477
0
    sal_Int16 nCharEscapement = 0;
478
0
    xProperties[0]->getPropertyValue(u"CharEscapement"_ustr) >>= nCharEscapement;
479
0
    for (std::size_t i = 0; i < xProperties.size(); i++)
480
0
    {
481
0
        if (nCharEscapement < 0)
482
0
        {
483
0
            xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0)));
484
0
            xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr,
485
0
                                             css::uno::Any(sal_Int8(100)));
486
0
        }
487
0
        else
488
0
        {
489
0
            xProperties[i]->setPropertyValue(u"CharEscapement"_ustr,
490
0
                                             css::uno::Any(sal_Int16(-14000)));
491
0
            xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr,
492
0
                                             css::uno::Any(sal_Int8(58)));
493
0
        }
494
0
    }
495
0
}
496
497
void ChartController::executeDispatch_Paste()
498
0
{
499
0
    SolarMutexGuard aGuard;
500
0
    auto pChartWindow(GetChartWindow());
501
0
    if( !pChartWindow )
502
0
        return;
503
504
0
    Graphic aGraphic;
505
    // paste location: center of window
506
0
    Point aPos = pChartWindow->PixelToLogic( tools::Rectangle(Point{}, pChartWindow->GetSizePixel()).Center());
507
508
    // handle different formats
509
0
    TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pChartWindow ));
510
0
    if( aDataHelper.GetTransferable().is())
511
0
    {
512
0
        if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
513
0
        {
514
0
            if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING) )
515
0
            {
516
0
                xStm->Seek( 0 );
517
0
                Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
518
519
0
                std::unique_ptr< SdrModel > spModel(
520
0
                    new SdrModel());
521
522
0
                if ( SvxDrawingLayerImport( spModel.get(), xInputStream ) )
523
0
                {
524
0
                    impl_PasteShapes( spModel.get() );
525
0
                }
526
0
            }
527
0
        }
528
0
        else if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
529
0
        {
530
            // graphic exchange format (graphic manager bitmap format?)
531
0
            if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB ))
532
0
            {
533
0
                TypeSerializer aSerializer(*xStm);
534
0
                aSerializer.readGraphic(aGraphic);
535
0
            }
536
0
        }
537
0
        else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ))
538
0
        {
539
            // meta file
540
0
            GDIMetaFile aMetafile;
541
0
            if( aDataHelper.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMetafile ))
542
0
                aGraphic = Graphic( aMetafile );
543
0
        }
544
0
        else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ))
545
0
        {
546
            // bitmap (non-graphic-manager)
547
0
            BitmapEx aBmpEx;
548
0
            if( aDataHelper.GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ))
549
0
                aGraphic = Graphic( aBmpEx );
550
0
        }
551
0
        else if( aDataHelper.HasFormat( SotClipboardFormatId::STRING ))
552
0
        {
553
0
            OUString aString;
554
0
            if( aDataHelper.GetString( SotClipboardFormatId::STRING, aString ) && m_pDrawModelWrapper )
555
0
            {
556
0
                if( m_pDrawViewWrapper )
557
0
                {
558
0
                    OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
559
0
                    if (pOutlinerView)//in case of edit mode insert the formatted string
560
0
                        pOutlinerView->PasteSpecial();
561
0
                    else
562
0
                    {
563
0
                        impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) );
564
0
                    }
565
0
                }
566
0
            }
567
0
        }
568
0
    }
569
570
0
    if( aGraphic.GetType() != GraphicType::NONE )
571
0
    {
572
0
        Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic());
573
0
        if( xGraphic.is())
574
0
            impl_PasteGraphic( xGraphic, aPos );
575
0
    }
576
0
}
577
578
// note: aPosition is ignored for now. The object is always pasted centered to
579
// the page
580
void ChartController::impl_PasteGraphic(
581
    uno::Reference< graphic::XGraphic > const & xGraphic,
582
    const ::Point & /* aPosition */ )
583
0
{
584
0
    DBG_TESTSOLARMUTEX();
585
    // note: the XPropertySet of the model is the old API. Also the property
586
    // "AdditionalShapes" that is used there.
587
0
    rtl::Reference< ChartModel > xModel = getChartModel();
588
0
    DrawModelWrapper * pDrawModelWrapper( GetDrawModelWrapper());
589
0
    if( ! (xGraphic.is() && xModel.is()))
590
0
        return;
591
0
    rtl::Reference<SvxGraphicObject> xGraphicShape = new SvxGraphicObject(nullptr);
592
0
    xGraphicShape->setShapeKind(SdrObjKind::Graphic);
593
594
0
    rtl::Reference< SvxDrawPage > xPage = pDrawModelWrapper->getMainDrawPage();
595
0
    if( xPage.is())
596
0
    {
597
0
        xPage->add( xGraphicShape );
598
        //need to change the model state manually
599
0
        xModel->setModified( true );
600
        //select new shape
601
0
        m_aSelection.setSelection( xGraphicShape );
602
0
        m_aSelection.applySelection( m_pDrawViewWrapper.get() );
603
0
    }
604
0
    xGraphicShape->SvxShape::setPropertyValue( u"Graphic"_ustr, uno::Any( xGraphic ));
605
606
0
    awt::Size aGraphicSize( 1000, 1000 );
607
0
    bool bGotGraphicSize = false;
608
0
    try
609
0
    {
610
0
        bGotGraphicSize = xGraphicShape->SvxShape::getPropertyValue( u"Size100thMM"_ustr) >>= aGraphicSize;
611
0
    }
612
0
    catch (css::beans::UnknownPropertyException& )
613
0
    {}
614
0
    auto pChartWindow(GetChartWindow());
615
    // first try size in 100th mm, then pixel size
616
0
    if( !bGotGraphicSize )
617
0
    {
618
0
        bool bGotSizePixel = false;
619
0
        try
620
0
        {
621
0
            bGotSizePixel = xGraphicShape->SvxShape::getPropertyValue( u"SizePixel"_ustr) >>= aGraphicSize;
622
0
        }
623
0
        catch (css::beans::UnknownPropertyException& )
624
0
        {}
625
0
        if ( bGotSizePixel && pChartWindow )
626
0
        {
627
0
            ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
628
0
            aGraphicSize.Width = aVCLSize.getWidth();
629
0
            aGraphicSize.Height = aVCLSize.getHeight();
630
0
        }
631
0
    }
632
0
    xGraphicShape->setSize( aGraphicSize );
633
0
    xGraphicShape->setPosition( awt::Point( 0, 0 ) );
634
0
}
635
636
void ChartController::impl_PasteShapes( SdrModel* pModel )
637
0
{
638
0
    DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
639
0
    if ( !(pDrawModelWrapper && m_pDrawViewWrapper) )
640
0
        return;
641
642
0
    rtl::Reference< SvxDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() );
643
0
    SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage );
644
0
    if ( !pDestPage )
645
0
        return;
646
647
0
    Reference< drawing::XShape > xSelShape;
648
0
    m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
649
0
    sal_uInt16 nCount = pModel->GetPageCount();
650
0
    for ( sal_uInt16 i = 0; i < nCount; ++i )
651
0
    {
652
0
        const SdrPage* pPage = pModel->GetPage( i );
653
0
        SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
654
0
        while ( aIter.IsMore() )
655
0
        {
656
0
            SdrObject* pObj(aIter.Next());
657
            // Clone to new SdrModel
658
0
            rtl::Reference<SdrObject> pNewObj;
659
0
            if (pObj)
660
0
                pNewObj = pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel());
661
662
0
            if ( pNewObj )
663
0
            {
664
                // set position
665
0
                Reference< drawing::XShape > xShape( pNewObj->getUnoShape(), uno::UNO_QUERY );
666
0
                if ( xShape.is() )
667
0
                {
668
0
                    xShape->setPosition( awt::Point( 0, 0 ) );
669
0
                }
670
671
0
                pDestPage->InsertObject( pNewObj.get() );
672
0
                m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pNewObj ) );
673
0
                xSelShape = std::move(xShape);
674
0
            }
675
0
        }
676
0
    }
677
678
0
    rtl::Reference< ChartModel > xModifiable = getChartModel();
679
0
    if ( xModifiable.is() )
680
0
    {
681
0
        xModifiable->setModified( true );
682
0
    }
683
684
    // select last inserted shape
685
0
    m_aSelection.setSelection( xSelShape );
686
0
    m_aSelection.applySelection( m_pDrawViewWrapper.get() );
687
688
0
    m_pDrawViewWrapper->EndUndo();
689
690
0
    impl_switchDiagramPositioningToExcludingPositioning();
691
0
}
692
693
void ChartController::impl_PasteStringAsTextShape( const OUString& rString, const awt::Point& rPosition )
694
0
{
695
0
    DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
696
0
    if ( !(pDrawModelWrapper && m_pDrawViewWrapper) )
697
0
        return;
698
699
0
    const rtl::Reference< SvxDrawPage > xDrawPage( pDrawModelWrapper->getMainDrawPage() );
700
0
    OSL_ASSERT( xDrawPage.is() );
701
702
0
    if ( !xDrawPage )
703
0
        return;
704
705
0
    try
706
0
    {
707
0
        rtl::Reference<SvxShapeText> xTextShape = new SvxShapeText(nullptr);
708
0
        xTextShape->setShapeKind(SdrObjKind::Text);
709
0
        xDrawPage->add( xTextShape );
710
711
0
        xTextShape->setString( rString );
712
713
0
        float fCharHeight = 10.0;
714
0
        xTextShape->SvxShape::setPropertyValue( u"TextAutoGrowHeight"_ustr, uno::Any( true ) );
715
0
        xTextShape->SvxShape::setPropertyValue( u"TextAutoGrowWidth"_ustr, uno::Any( true ) );
716
0
        xTextShape->SvxShape::setPropertyValue( u"CharHeight"_ustr, uno::Any( fCharHeight ) );
717
0
        xTextShape->SvxShape::setPropertyValue( u"CharHeightAsian"_ustr, uno::Any( fCharHeight ) );
718
0
        xTextShape->SvxShape::setPropertyValue( u"CharHeightComplex"_ustr, uno::Any( fCharHeight ) );
719
0
        xTextShape->SvxShape::setPropertyValue( u"TextVerticalAdjust"_ustr, uno::Any( drawing::TextVerticalAdjust_CENTER ) );
720
0
        xTextShape->SvxShape::setPropertyValue( u"TextHorizontalAdjust"_ustr, uno::Any( drawing::TextHorizontalAdjust_CENTER ) );
721
0
        xTextShape->SvxShape::setPropertyValue( u"CharFontName"_ustr, uno::Any( u"Albany"_ustr ) );
722
723
0
        xTextShape->setPosition( rPosition );
724
725
0
        m_aSelection.setSelection( xTextShape );
726
0
        m_aSelection.applySelection( m_pDrawViewWrapper.get() );
727
728
0
        SdrObject* pObj = DrawViewWrapper::getSdrObject( xTextShape );
729
0
        if ( pObj )
730
0
        {
731
0
            m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
732
0
            m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
733
0
            m_pDrawViewWrapper->EndUndo();
734
735
0
            impl_switchDiagramPositioningToExcludingPositioning();
736
0
        }
737
0
    }
738
0
    catch ( const uno::Exception& )
739
0
    {
740
0
        DBG_UNHANDLED_EXCEPTION("chart2");
741
0
    }
742
0
}
743
744
void ChartController::executeDispatch_Copy()
745
0
{
746
0
    SolarMutexGuard aSolarGuard;
747
0
    if (!m_pDrawViewWrapper)
748
0
        return;
749
750
0
    OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
751
0
    if (pOutlinerView)
752
0
        pOutlinerView->Copy();
753
0
    else
754
0
    {
755
0
        SdrObject* pSelectedObj = nullptr;
756
0
        ObjectIdentifier aSelOID(m_aSelection.getSelectedOID());
757
758
0
        if (aSelOID.isAutoGeneratedObject())
759
0
            pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( aSelOID.getObjectCID() );
760
0
        else if (aSelOID.isAdditionalShape())
761
0
            pSelectedObj = DrawViewWrapper::getSdrObject( aSelOID.getAdditionalShape() );
762
763
0
        if (pSelectedObj)
764
0
        {
765
0
            Reference<datatransfer::clipboard::XClipboard> xClipboard(GetChartWindow()->GetClipboard());
766
0
            if (xClipboard.is())
767
0
            {
768
0
                Reference< datatransfer::XTransferable > xTransferable(
769
0
                    new ChartTransferable(m_pDrawModelWrapper->getSdrModel(),
770
0
                                          pSelectedObj, aSelOID.isAdditionalShape()));
771
0
                xClipboard->setContents(xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >());
772
0
            }
773
0
        }
774
0
    }
775
0
}
776
777
void ChartController::executeDispatch_Cut()
778
0
{
779
0
    executeDispatch_Copy();
780
0
    executeDispatch_Delete();
781
0
}
782
783
bool ChartController::isObjectDeleteable( const uno::Any& rSelection )
784
0
{
785
0
    ObjectIdentifier aSelOID( rSelection );
786
0
    if ( aSelOID.isAutoGeneratedObject() )
787
0
    {
788
0
        const OUString& aSelObjCID( aSelOID.getObjectCID() );
789
0
        ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
790
791
0
        switch(aObjectType)
792
0
        {
793
0
        case OBJECTTYPE_TITLE:
794
0
        case OBJECTTYPE_LEGEND:
795
0
        case OBJECTTYPE_DATA_SERIES:
796
0
        case OBJECTTYPE_LEGEND_ENTRY:
797
0
        case OBJECTTYPE_DATA_CURVE_EQUATION:
798
0
        case OBJECTTYPE_DATA_CURVE:
799
0
        case OBJECTTYPE_DATA_AVERAGE_LINE:
800
0
        case OBJECTTYPE_DATA_ERRORS_X:
801
0
        case OBJECTTYPE_DATA_ERRORS_Y:
802
0
        case OBJECTTYPE_DATA_ERRORS_Z:
803
0
        case OBJECTTYPE_DATA_LABELS:
804
0
        case OBJECTTYPE_DATA_LABEL:
805
0
        case OBJECTTYPE_AXIS:
806
0
        case OBJECTTYPE_GRID:
807
0
        case OBJECTTYPE_SUBGRID:
808
0
            return true;
809
0
        default:
810
0
            break;
811
0
        }
812
0
    }
813
0
    else if ( aSelOID.isAdditionalShape() )
814
0
    {
815
0
        return true;
816
0
    }
817
818
0
    return false;
819
0
}
820
821
bool ChartController::isShapeContext() const
822
0
{
823
0
    return m_aSelection.isAdditionalShapeSelected() ||
824
0
         ( m_pDrawViewWrapper && m_pDrawViewWrapper->GetMarkedObjectList().GetMarkCount() != 0 &&
825
0
           ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::Text ) );
826
0
}
827
828
bool ChartController::IsTextEdit() const
829
0
{
830
    // only Title objects and additional shapes are editable textshapes in chart
831
0
    return m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() &&
832
0
        (m_aSelection.isTitleObjectSelected() || m_aSelection.isAdditionalShapeSelected());
833
0
}
834
835
void ChartController::impl_ClearSelection()
836
0
{
837
0
    if( m_aSelection.hasSelection())
838
0
    {
839
0
        m_aSelection.clearSelection();
840
0
        impl_notifySelectionChangeListeners();
841
0
    }
842
0
}
843
844
bool ChartController::executeDispatch_Delete()
845
0
{
846
0
    bool bReturn = false;
847
848
    // remove the selected object
849
0
    OUString aCID( m_aSelection.getSelectedCID() );
850
0
    if( !aCID.isEmpty() )
851
0
    {
852
0
        if( !isObjectDeleteable( uno::Any( aCID ) ) )
853
0
            return false;
854
855
        //remove chart object
856
0
        rtl::Reference< ChartModel > xChartDoc = getChartModel();
857
0
        if( !xChartDoc.is() )
858
0
            return false;
859
860
0
        ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID ));
861
0
        switch( aObjectType )
862
0
        {
863
0
            case OBJECTTYPE_TITLE:
864
0
            {
865
0
                UndoGuard aUndoGuard(
866
0
                    ActionDescriptionProvider::createDescription(
867
0
                        ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_TITLE )),
868
0
                    m_xUndoManager );
869
0
                TitleHelper::removeTitle(
870
0
                    ObjectIdentifier::getTitleTypeForCID( aCID ), getChartModel() );
871
0
                bReturn = true;
872
0
                aUndoGuard.commit();
873
0
                break;
874
0
            }
875
0
            case OBJECTTYPE_LEGEND:
876
0
            {
877
0
                rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram());
878
0
                if( xDiagram.is())
879
0
                {
880
0
                    rtl::Reference< Legend > xLegend( xDiagram->getLegend2() );
881
0
                    if( xLegend.is())
882
0
                    {
883
0
                        UndoGuard aUndoGuard(
884
0
                            ActionDescriptionProvider::createDescription(
885
0
                                ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
886
0
                            m_xUndoManager );
887
0
                        xLegend->setPropertyValue( u"Show"_ustr, uno::Any( false ));
888
0
                        bReturn = true;
889
0
                        aUndoGuard.commit();
890
0
                    }
891
0
                }
892
0
                break;
893
0
            }
894
895
0
            case OBJECTTYPE_DATA_SERIES:
896
0
                bReturn = lcl_deleteDataSeries( aCID, getChartModel(), m_xUndoManager );
897
0
                break;
898
899
0
            case OBJECTTYPE_LEGEND_ENTRY:
900
0
            {
901
0
                ObjectType eParentObjectType = ObjectIdentifier::getObjectType(
902
0
                    ObjectIdentifier::getFullParentParticle( aCID ));
903
0
                if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
904
0
                {
905
0
                    bReturn = lcl_deleteDataSeries( aCID, getChartModel(), m_xUndoManager );
906
0
                }
907
0
                else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
908
0
                {
909
0
                    sal_Int32 nEndPos = aCID.lastIndexOf(':');
910
0
                    OUString aParentCID = aCID.copy(0, nEndPos);
911
912
0
                    bReturn = lcl_deleteDataCurve(aParentCID, getChartModel(), m_xUndoManager );
913
0
                }
914
0
                else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
915
0
                {
916
0
                    executeDispatch_DeleteMeanValue();
917
0
                    bReturn = true;
918
0
                }
919
0
                break;
920
0
            }
921
922
0
            case OBJECTTYPE_DATA_AVERAGE_LINE:
923
0
            {
924
0
                uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
925
0
                    ObjectIdentifier::getObjectPropertySet(
926
0
                        ObjectIdentifier::getFullParentParticle( aCID ), getChartModel()), uno::UNO_QUERY );
927
0
                if( xRegCurveCnt.is())
928
0
                {
929
0
                    UndoGuard aUndoGuard(
930
0
                        ActionDescriptionProvider::createDescription(
931
0
                            ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
932
0
                        m_xUndoManager );
933
0
                    RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
934
0
                    bReturn = true;
935
0
                    aUndoGuard.commit();
936
0
                }
937
0
            }
938
0
            break;
939
940
0
            case OBJECTTYPE_DATA_CURVE:
941
0
            {
942
0
                bReturn = lcl_deleteDataCurve( aCID, getChartModel(), m_xUndoManager );
943
0
            }
944
0
            break;
945
946
0
            case OBJECTTYPE_DATA_CURVE_EQUATION:
947
0
            {
948
0
                uno::Reference< beans::XPropertySet > xEqProp(
949
0
                    ObjectIdentifier::getObjectPropertySet( aCID, getChartModel()));
950
951
0
                if( xEqProp.is())
952
0
                {
953
0
                    rtl::Reference<::chart::ChartModel> xModel( getChartModel() );
954
0
                    UndoGuard aUndoGuard(
955
0
                        ActionDescriptionProvider::createDescription(
956
0
                            ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
957
0
                        m_xUndoManager );
958
0
                    {
959
0
                        ControllerLockGuardUNO aCtlLockGuard( xModel );
960
0
                        xEqProp->setPropertyValue( u"ShowEquation"_ustr, uno::Any( false ));
961
0
                        xEqProp->setPropertyValue( u"XName"_ustr, uno::Any( u"x"_ustr ));
962
0
                        xEqProp->setPropertyValue( u"YName"_ustr, uno::Any( u"f(x)"_ustr ));
963
0
                        xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( false ));
964
0
                    }
965
0
                    bReturn = true;
966
0
                    aUndoGuard.commit();
967
0
                }
968
0
            }
969
0
            break;
970
971
0
            case OBJECTTYPE_DATA_ERRORS_X:
972
0
            case OBJECTTYPE_DATA_ERRORS_Y:
973
0
            case OBJECTTYPE_DATA_ERRORS_Z:
974
0
            {
975
0
                uno::Reference< beans::XPropertySet > xErrorBarProp(
976
0
                    ObjectIdentifier::getObjectPropertySet( aCID, getChartModel() ));
977
0
                if( xErrorBarProp.is())
978
0
                {
979
0
                    TranslateId pId;
980
981
0
                    if ( aObjectType == OBJECTTYPE_DATA_ERRORS_X )
982
0
                        pId = STR_OBJECT_ERROR_BARS_X;
983
0
                    else if ( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
984
0
                        pId = STR_OBJECT_ERROR_BARS_Y;
985
0
                    else
986
0
                        pId = STR_OBJECT_ERROR_BARS_Z;
987
988
0
                    rtl::Reference<::chart::ChartModel> xModel( getChartModel() );
989
0
                    UndoGuard aUndoGuard(
990
0
                        ActionDescriptionProvider::createDescription(
991
0
                            ActionDescriptionProvider::ActionType::Delete, SchResId(pId)),
992
0
                        m_xUndoManager);
993
0
                    {
994
0
                        ControllerLockGuardUNO aCtlLockGuard( xModel );
995
0
                        xErrorBarProp->setPropertyValue(
996
0
                            u"ErrorBarStyle"_ustr,
997
0
                            uno::Any( css::chart::ErrorBarStyle::NONE ));
998
0
                    }
999
0
                    bReturn = true;
1000
0
                    aUndoGuard.commit();
1001
0
                }
1002
0
                break;
1003
0
            }
1004
1005
0
            case OBJECTTYPE_DATA_LABELS:
1006
0
            case OBJECTTYPE_DATA_LABEL:
1007
0
            {
1008
0
                uno::Reference< beans::XPropertySet > xObjectProperties =
1009
0
                    ObjectIdentifier::getObjectPropertySet( aCID, getChartModel() );
1010
0
                if( xObjectProperties.is() )
1011
0
                {
1012
0
                    UndoGuard aUndoGuard(
1013
0
                        ActionDescriptionProvider::createDescription(
1014
0
                        ActionDescriptionProvider::ActionType::Delete,
1015
0
                            SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )),
1016
0
                                m_xUndoManager );
1017
0
                    chart2::DataPointLabel aLabel;
1018
0
                    xObjectProperties->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel;
1019
0
                    aLabel.ShowNumber = false;
1020
0
                    aLabel.ShowNumberInPercent = false;
1021
0
                    aLabel.ShowCategoryName = false;
1022
0
                    aLabel.ShowLegendSymbol = false;
1023
0
                    aLabel.ShowCustomLabel = false;
1024
0
                    aLabel.ShowSeriesName = false;
1025
0
                    if( aObjectType == OBJECTTYPE_DATA_LABELS )
1026
0
                    {
1027
0
                        rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() );
1028
0
                        xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_LABEL, uno::Any(aLabel) );
1029
0
                        xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() );
1030
0
                    }
1031
0
                    else
1032
0
                    {
1033
0
                        xObjectProperties->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabel));
1034
0
                        xObjectProperties->setPropertyValue(CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any());
1035
0
                    }
1036
0
                    bReturn = true;
1037
0
                    aUndoGuard.commit();
1038
0
                }
1039
0
                break;
1040
0
            }
1041
0
            case OBJECTTYPE_AXIS:
1042
0
            {
1043
0
                executeDispatch_DeleteAxis();
1044
0
                bReturn = true;
1045
0
                break;
1046
0
            }
1047
0
            case OBJECTTYPE_GRID:
1048
0
            {
1049
0
                executeDispatch_DeleteMajorGrid();
1050
0
                bReturn = true;
1051
0
                break;
1052
0
            }
1053
0
            case OBJECTTYPE_SUBGRID:
1054
0
            {
1055
0
                executeDispatch_DeleteMinorGrid();
1056
0
                bReturn = true;
1057
0
                break;
1058
0
            }
1059
1060
0
            default:
1061
0
            {
1062
0
                break;
1063
0
            }
1064
0
        }
1065
0
    }
1066
0
    else
1067
0
    {
1068
        //remove additional shape
1069
0
        impl_ClearSelection();
1070
0
        {
1071
0
            SolarMutexGuard aSolarGuard;
1072
0
            if ( m_pDrawViewWrapper )
1073
0
            {
1074
0
                m_pDrawViewWrapper->DeleteMarked();
1075
0
                bReturn = true;
1076
0
            }
1077
0
        }
1078
0
    }
1079
0
    return bReturn;
1080
0
}
1081
1082
void ChartController::executeDispatch_ToggleLegend()
1083
0
{
1084
0
    rtl::Reference< ChartModel > xModel = getChartModel();
1085
0
    UndoGuard aUndoGuard(
1086
0
        SchResId( STR_ACTION_TOGGLE_LEGEND ), m_xUndoManager );
1087
0
    rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*xModel);
1088
0
    bool bChanged = false;
1089
0
    if( xLegendProp.is())
1090
0
    {
1091
0
        try
1092
0
        {
1093
0
            bool bShow = false;
1094
0
            if( xLegendProp->getPropertyValue( u"Show"_ustr) >>= bShow )
1095
0
            {
1096
0
                xLegendProp->setPropertyValue( u"Show"_ustr, uno::Any( ! bShow ));
1097
0
                bChanged = true;
1098
0
            }
1099
0
        }
1100
0
        catch( const uno::Exception & )
1101
0
        {
1102
0
            DBG_UNHANDLED_EXCEPTION("chart2");
1103
0
        }
1104
0
    }
1105
0
    else
1106
0
    {
1107
0
        xLegendProp = LegendHelper::getLegend(*xModel, m_xCC, true);
1108
0
        if( xLegendProp.is())
1109
0
            bChanged = true;
1110
0
    }
1111
1112
0
    if( bChanged )
1113
0
        aUndoGuard.commit();
1114
0
}
1115
1116
void ChartController::executeDispatch_ToggleGridHorizontal()
1117
0
{
1118
0
    UndoGuard aUndoGuard(
1119
0
        SchResId( STR_ACTION_TOGGLE_GRID_HORZ ), m_xUndoManager );
1120
0
    rtl::Reference< Diagram > xDiagram( getFirstDiagram() );
1121
0
    if( !xDiagram.is())
1122
0
        return;
1123
1124
0
    sal_Int32 nDimensionIndex = 1;
1125
0
    sal_Int32 nCooSysIndex = 0;
1126
1127
0
    bool bHasMajorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true,  xDiagram );
1128
0
    bool bHasMinorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
1129
1130
0
    if( bHasMajorYGrid )
1131
0
    {
1132
0
        if ( bHasMinorYGrid )
1133
0
        {
1134
0
            AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true,  xDiagram );
1135
0
            AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
1136
0
        }
1137
0
        else
1138
0
        {
1139
0
            AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
1140
0
        }
1141
0
    }
1142
0
    else
1143
0
    {
1144
0
        AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
1145
0
    }
1146
0
    aUndoGuard.commit();
1147
0
}
1148
1149
void ChartController::executeDispatch_ToggleGridVertical()
1150
0
{
1151
0
    UndoGuard aUndoGuard(
1152
0
        SchResId( STR_ACTION_TOGGLE_GRID_VERTICAL ), m_xUndoManager );
1153
0
    rtl::Reference< Diagram > xDiagram( getFirstDiagram() );
1154
0
    if( !xDiagram.is())
1155
0
        return;
1156
1157
0
    sal_Int32 nDimensionIndex = 0;
1158
0
    sal_Int32 nCooSysIndex = 0;
1159
1160
0
    bool bHasMajorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true,  xDiagram );
1161
0
    bool bHasMinorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
1162
0
    if( bHasMajorXGrid )
1163
0
    {
1164
0
        if (bHasMinorXGrid)
1165
0
        {
1166
0
            AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true,  xDiagram );
1167
0
            AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
1168
0
        }
1169
0
        else
1170
0
        {
1171
0
            AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
1172
0
        }
1173
0
    }
1174
0
    else
1175
0
    {
1176
0
        AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
1177
0
    }
1178
1179
0
    aUndoGuard.commit();
1180
0
}
1181
1182
void ChartController::executeDispatch_FillColor(sal_uInt32 nColor)
1183
0
{
1184
0
    try
1185
0
    {
1186
0
        OUString aCID( m_aSelection.getSelectedCID() );
1187
0
        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1188
0
        if( xChartModel.is() )
1189
0
        {
1190
0
            Reference< beans::XPropertySet > xPointProperties(
1191
0
                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1192
0
            if( xPointProperties.is() )
1193
0
                xPointProperties->setPropertyValue( u"FillColor"_ustr, uno::Any( nColor ) );
1194
1195
0
            ObjectType eType = ObjectIdentifier::getObjectType(aCID);
1196
0
            if (eType == OBJECTTYPE_DATA_SERIES || eType == OBJECTTYPE_DATA_POINT)
1197
0
            {
1198
0
                xChartModel->clearColorPalette();
1199
0
            }
1200
0
        }
1201
0
    }
1202
0
    catch( const uno::Exception& )
1203
0
    {
1204
0
        DBG_UNHANDLED_EXCEPTION( "chart2" );
1205
0
    }
1206
0
}
1207
1208
void ChartController::executeDispatch_FillGradient(std::u16string_view sJSONGradient)
1209
0
{
1210
0
    basegfx::BGradient aBGradient = basegfx::BGradient::fromJSON(sJSONGradient);
1211
0
    css::awt::Gradient aGradient = model::gradient::createUnoGradient2(aBGradient);
1212
1213
0
    try
1214
0
    {
1215
0
        OUString aCID( m_aSelection.getSelectedCID() );
1216
0
        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1217
1218
0
        if( xChartModel.is() )
1219
0
        {
1220
0
            Reference< beans::XPropertySet > xPropSet(
1221
0
                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1222
1223
0
            if( xPropSet.is() )
1224
0
            {
1225
0
                OUString aPrefferedName =
1226
0
                    OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().front().getStopColor())))
1227
0
                    + OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().back().getStopColor())))
1228
0
                    + OUString::number(static_cast<sal_Int32>(aBGradient.GetAngle().get()));
1229
1230
0
                OUString aNewName = PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient),
1231
0
                                        xChartModel,
1232
0
                                        aPrefferedName);
1233
1234
0
                xPropSet->setPropertyValue(u"FillGradientName"_ustr, css::uno::Any(aNewName));
1235
0
            }
1236
0
        }
1237
0
    }
1238
0
    catch( const uno::Exception & )
1239
0
    {
1240
0
        TOOLS_WARN_EXCEPTION("chart2", "" );
1241
0
    }
1242
0
}
1243
1244
void ChartController::executeDispatch_LineColor(sal_uInt32 nColor)
1245
0
{
1246
0
    try
1247
0
    {
1248
0
        OUString aCID( m_aSelection.getSelectedCID() );
1249
0
        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1250
0
        if( xChartModel.is() )
1251
0
        {
1252
0
            Reference< beans::XPropertySet > xPropSet(
1253
0
                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1254
1255
0
            ObjectType eType = ObjectIdentifier::getObjectType(aCID);
1256
0
            if (eType == OBJECTTYPE_DIAGRAM)
1257
0
            {
1258
0
                css::uno::Reference<css::chart2::XDiagram> xDiagram(
1259
0
                        xPropSet, css::uno::UNO_QUERY);
1260
0
                if (xDiagram.is())
1261
0
                    xPropSet.set(xDiagram->getWall());
1262
0
            }
1263
1264
0
            if( xPropSet.is() )
1265
0
                xPropSet->setPropertyValue( u"LineColor"_ustr, css::uno::Any( Color(ColorTransparency, nColor) ) );
1266
0
        }
1267
0
    }
1268
0
    catch( const uno::Exception& )
1269
0
    {
1270
0
        DBG_UNHANDLED_EXCEPTION( "chart2" );
1271
0
    }
1272
0
}
1273
1274
void ChartController::executeDispatch_LineWidth(sal_uInt32 nWidth)
1275
0
{
1276
0
    try
1277
0
    {
1278
0
        OUString aCID( m_aSelection.getSelectedCID() );
1279
0
        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1280
0
        if( xChartModel.is() )
1281
0
        {
1282
0
            Reference< beans::XPropertySet > xPropSet(
1283
0
                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1284
1285
0
            ObjectType eType = ObjectIdentifier::getObjectType(aCID);
1286
0
            if (eType == OBJECTTYPE_DIAGRAM)
1287
0
            {
1288
0
                css::uno::Reference<css::chart2::XDiagram> xDiagram(
1289
0
                        xPropSet, css::uno::UNO_QUERY);
1290
0
                if (xDiagram.is())
1291
0
                    xPropSet.set(xDiagram->getWall());
1292
0
            }
1293
1294
0
            if( xPropSet.is() )
1295
0
                xPropSet->setPropertyValue( u"LineWidth"_ustr, css::uno::Any( nWidth ) );
1296
0
        }
1297
0
    }
1298
0
    catch( const uno::Exception& )
1299
0
    {
1300
0
        DBG_UNHANDLED_EXCEPTION( "chart2" );
1301
0
    }
1302
0
}
1303
1304
void ChartController::executeDispatch_LOKSetTextSelection(int nType, int nX, int nY)
1305
0
{
1306
0
    if (!m_pDrawViewWrapper)
1307
0
        return;
1308
1309
0
    if (!m_pDrawViewWrapper->IsTextEdit())
1310
0
        return;
1311
1312
0
    OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
1313
0
    if (!pOutlinerView)
1314
0
        return;
1315
1316
0
    EditView& rEditView = pOutlinerView->GetEditView();
1317
0
    Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
1318
0
    switch (nType)
1319
0
    {
1320
0
        case LOK_SETTEXTSELECTION_START:
1321
0
            rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
1322
0
            break;
1323
0
        case LOK_SETTEXTSELECTION_END:
1324
0
            rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
1325
0
            break;
1326
0
        case LOK_SETTEXTSELECTION_RESET:
1327
0
            rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
1328
0
            break;
1329
0
        default:
1330
0
            assert(false);
1331
0
            break;
1332
0
    }
1333
0
}
1334
1335
void ChartController::executeDispatch_LOKPieSegmentDragging( int nOffset )
1336
0
{
1337
0
    try
1338
0
    {
1339
0
        OUString aCID( m_aSelection.getSelectedCID() );
1340
0
        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
1341
0
        if( xChartModel.is() )
1342
0
        {
1343
0
            Reference< beans::XPropertySet > xPointProperties(
1344
0
                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1345
0
            if( xPointProperties.is() )
1346
0
                xPointProperties->setPropertyValue( u"Offset"_ustr, uno::Any( nOffset / 100.0 ) );
1347
0
        }
1348
0
    }
1349
0
    catch( const uno::Exception & )
1350
0
    {
1351
0
        TOOLS_WARN_EXCEPTION("chart2", "" );
1352
0
    }
1353
0
}
1354
1355
void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const Sequence< beans::PropertyValue >& rArgs )
1356
0
{
1357
0
    Reference< frame::XDispatch > xDispatch( m_aDispatchContainer.getShapeController() );
1358
0
    if ( xDispatch.is() )
1359
0
    {
1360
0
        xDispatch->dispatch( rURL, rArgs );
1361
0
    }
1362
0
}
1363
1364
void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
1365
0
{
1366
0
    UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
1367
0
        ActionDescriptionProvider::ActionType::PosSize,
1368
0
        ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)),
1369
0
        m_xUndoManager );
1370
0
    if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), true, true))
1371
0
        aUndoGuard.commit();
1372
0
}
1373
1374
} //  namespace chart
1375
1376
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */