Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svx/diagram/DiagramHelper_svx.hxx
Line
Count
Source
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
#pragma once
21
22
#include <vector>
23
#include <svx/svxdllapi.h>
24
#include <rtl/ustring.hxx>
25
#include <svx/svdhdl.hxx>
26
#include <svx/diagram/DomMapFlag.hxx>
27
28
// Forward declarations
29
class SdrObjGroup;
30
31
namespace svx { namespace diagram {
32
33
// Helper class to visualize an imminently recognizable
34
// additional visualization for DynamicDiagrams that can also
35
// be used to show/hide the DiagramDialog by the user
36
// Note: is also used as additional drag/move handle
37
class SVXCORE_DLLPUBLIC DiagramFrameHdl final : public SdrHdl
38
{
39
    // object dimensions
40
    basegfx::B2DHomMatrix maTransformation;
41
42
    // create marker for this kind
43
    virtual void CreateB2dIAObject() override;
44
45
public:
46
    DiagramFrameHdl(const basegfx::B2DHomMatrix& rTransformation);
47
48
    static void clicked(const Point& rPnt);
49
};
50
51
class DiagramDataState;
52
53
// Helper class to allow administer advanced Diagram related
54
// data and functionality
55
class SVXCORE_DLLPUBLIC DiagramHelper_svx
56
{
57
private:
58
    OUString msSelectedModelID;
59
60
    // These values define behaviour to where take data from at re-creation time.
61
    // Different definitions will have different consequences for re-creation
62
    // of Diagram visualization (if needed/triggered).
63
    // The style attributes per shape e.g. can be re-stored frm either an
64
    // existing Theme, or the preserved key/value list of properties per XShape.
65
    // With the current default settings the re-creation uses the preserved
66
    // key/value pairs, but re-creation from Theme may also be desirable. It
67
    // is also good to preserve both data packages at initial import to allow
68
    // alternatively one of these two methods for re-construction
69
70
    // If true, the oox::Theme data from ::DiagramData get/set/ThemeDocument()
71
    // aka mxThemeDocument - if it exists - will be used to create the style
72
    // attributes for the to-be-created XShapes (theoretically allows re-creation
73
    // with other Theme)
74
    bool mbUseDiagramThemeData; // false
75
76
    // If true, the UNO API form of attributes per Point as Key/value list
77
    // that was secured after initial XShape creation is used to create the
78
    // style attributes for the to-be-created XShapes
79
    bool mbUseDiagramModelData; // true
80
81
    // If true and mxThemeDocument exists it will be re-imported to
82
    // a newly created oox::drawingml::Theme object
83
    bool mbForceThemePtrRecreation; // false
84
85
    // flag to remember if locking of scale/translate was
86
    // already done
87
    bool mbDiagramObjectsLocked : 1;
88
89
protected:
90
    // helpers
91
    void applyLocksToDiagramObjects(bool bActivate);
92
93
    // access associated SdrObjGroup/XShape/RootShape
94
    virtual css::uno::Reference< css::drawing::XShape >& accessRootShape() = 0;
95
96
    // Make constructor protected to signal that this anyway pure virtual class
97
    // shall not be incarnated - target to use is oox::drawingml::DiagramHelper_oox
98
    DiagramHelper_svx();
99
    explicit DiagramHelper_svx(DiagramHelper_svx const& rSource);
100
101
public:
102
    virtual ~DiagramHelper_svx();
103
104
    // re-create XShapes
105
    virtual void reLayout() = 0;
106
107
    // get children of provided data node
108
    // use empty string for top-level nodes
109
    // returns vector of (id, text)
110
    virtual std::vector<std::pair<OUString, OUString>>
111
    getDiagramChildren(const OUString& rParentId) const = 0;
112
113
    // add/remove new top-level node to data model, returns its id
114
    virtual OUString addDiagramNode(const OUString& rText, SdrModel& rDrawModel) = 0;
115
    virtual bool removeDiagramNode(const OUString& rNodeId, SdrModel& rDrawModel) = 0;
116
    virtual void TextInformationChange() = 0;
117
    virtual void ItemSetInformationChange(std::span< const SfxPoolItem* const > aChangedItems) = 0;
118
119
    // Undo/Redo helpers for extracting/restoring Diagram-defining data
120
    virtual std::shared_ptr<svx::diagram::DiagramDataState> extractDiagramDataState() const = 0;
121
    virtual void applyDiagramDataState(const std::shared_ptr<svx::diagram::DiagramDataState>& rState) = 0;
122
123
0
    bool UseDiagramThemeData() const { return mbUseDiagramThemeData; }
124
0
    bool ForceThemePtrRecreation() const { return mbForceThemePtrRecreation; };
125
126
    // connect/disconnect to/from Group
127
    void connectToSdrObjGroup(
128
        const css::uno::Reference< css::drawing::XShape >& rTarget,
129
        std::shared_ptr< svx::diagram::DiagramHelper_svx >* mpDiagramHelperFromUndo);
130
    void disconnectFromSdrObjGroup(bool bEnableUndo);
131
132
    void AddAdditionalVisualization(SdrHdlList& rHdlList);
133
134
    // access to PropertyValues
135
    virtual css::uno::Any getOOXDomValue(svx::diagram::DomMapFlag aDomMapFlag) const = 0;
136
137
    // check if mandatory DiagramDomS exist and/or were not touched
138
    virtual bool checkMinimalDataDoms() const = 0;
139
140
    // access to RootShape - the GroupObject used to host this Diagram
141
0
    css::uno::Reference< css::drawing::XShape >& getRootShape() { return accessRootShape(); }
142
143
    // needed to create DiagramHelper_oox in svx' SdrObjGroup copy constructor
144
    virtual DiagramHelper_svx* clone() const = 0;
145
146
    // write data to boost::property_tree
147
    virtual void addDiagramModelData(boost::property_tree::ptree& rTarget) const = 0;
148
    virtual OUString getDiagramModelData(svx::diagram::DomMapFlag aId) const = 0;
149
150
    virtual const OUString& getBackgroundShapeModelID() const = 0;
151
    virtual bool isTextNodeModelID(const OUString& rModelID) const = 0;
152
153
    const OUString& getSelectedModelID() const;
154
0
    void setSelectedModelID(const OUString& rNew) { msSelectedModelID = rNew; }
155
    SdrObject* getDiagramSubSelection();
156
    void markDirectDiagramSubSelection(SdrObject& rCandidate);
157
    bool markNextDiagramSubSelection(bool bPrev);
158
    void initSelectionByKeyboard(bool bPrev);
159
160
    // simple access to AssociatedRootShape
161
    SdrObjGroup* getAssociatedRootShape();
162
};
163
164
class SVXCORE_DLLPUBLIC DiagramHelperFactory_svx
165
{
166
protected:
167
    // do prohibit direct instantiation, only DiagramHelper_oox is intended
168
    DiagramHelperFactory_svx();
169
170
    // keep global var of this module hidden
171
    static DiagramHelperFactory_svx* pSingleGlobalDiagramHelperFactory_svx;
172
173
public:
174
    // try to access global static single instance of DiagramHelperFactory
175
    static DiagramHelperFactory_svx& getDiagramHelperFactory_svx();
176
177
    // virtual call to instantiate a new DiagramHelper, overloaded in oox to
178
    // allow instantiation of a DiagramHelper_oox
179
    virtual std::shared_ptr<svx::diagram::DiagramHelper_svx> createDiagramHelper_svx(boost::property_tree::ptree& rTarget) const = 0;
180
    virtual std::shared_ptr<svx::diagram::DiagramHelper_svx> createDiagramHelper_svx(std::u16string_view rLayout, std::u16string_view rData, std::u16string_view rColors, std::u16string_view rQuickstyle) const = 0;
181
};
182
183
}} // end of namespace
184
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */