Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/starmath/inc/document.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 <rtl/strbuf.hxx>
23
#include <sfx2/docfac.hxx>
24
#include <sfx2/objsh.hxx>
25
#include <svl/lstner.hxx>
26
#include <svl/itempool.hxx>
27
#include <sax/fshelper.hxx>
28
#include <unotools/lingucfg.hxx>
29
#include <oox/core/filterbase.hxx>
30
#include <oox/export/utils.hxx>
31
32
#include "format.hxx"
33
#include "node.hxx"
34
#include "parsebase.hxx"
35
#include "smdllapi.hxx"
36
#include "mathml/iterator.hxx"
37
38
class SfxPrinter;
39
class Printer;
40
class SmCursor;
41
42
namespace oox::formulaimport { class XmlStream; }
43
44
0
#define STAROFFICE_XML  "StarOffice XML (Math)"
45
inline constexpr OUString MATHML_XML = u"MathML XML (Math)"_ustr;
46
47
/* Access to printer should happen through this class only
48
 * ==========================================================================
49
 *
50
 * The printer can belong to the document or the OLE-Container. If the document
51
 * is an OLE-Document the printer generally belongs to the container too.
52
 * But the container maybe works with a different MapUnit than the server.
53
 * Referring to the MapMode the printer will be accordingly adjusted in the
54
 * constructor and restored in the destructor. This brings that this class
55
 * is always allowed to exists only a short time (e.g. while painting).
56
 * The control whether the printer is self-generated, gotten from the server
57
 * or is NULL then, is taken by the DocShell in the method GetPrt(), for
58
 * which the access is friend of the DocShell too.
59
 */
60
61
class SmDocShell;
62
class EditEngine;
63
class SmEditEngine;
64
class SmPrintUIOptions;
65
66
class SmPrinterAccess
67
{
68
    VclPtr<Printer> pPrinter;
69
    VclPtr<OutputDevice> pRefDev;
70
public:
71
    explicit SmPrinterAccess( SmDocShell &rDocShell );
72
    ~SmPrinterAccess();
73
0
    Printer* GetPrinter()  { return pPrinter.get(); }
74
5.17k
    OutputDevice* GetRefDev()  { return pRefDev.get(); }
75
};
76
77
78
class SM_DLLPUBLIC SmDocShell final : public SfxObjectShell, public SfxListener
79
{
80
    friend class SmPrinterAccess;
81
    friend class SmCursor;
82
83
    OUString            maText;
84
    SmFormat            maFormat;
85
    OUString            maAccText;
86
    SvtLinguOptions     maLinguOptions;
87
    std::unique_ptr<SmTableNode> mpTree;
88
    SmMlElement* m_pMlElementTree;
89
    rtl::Reference<SfxItemPool> mpEditEngineItemPool;
90
    std::unique_ptr<SmEditEngine> mpEditEngine;
91
    VclPtr<SfxPrinter>  mpPrinter;       //q.v. comment to SmPrinter Access!
92
    VclPtr<Printer>     mpTmpPrinter;    //ditto
93
    sal_uInt16          mnModifyCount;
94
    bool                mbFormulaArranged;
95
    sal_Int16           mnSmSyntaxVersion;
96
    std::unique_ptr<AbstractSmParser> maParser;
97
    std::unique_ptr<SmCursor> mpCursor;
98
    std::set< OUString >    maUsedSymbols;   // to export used symbols only when saving
99
100
101
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
102
103
    bool        WriteAsMathType3( SfxMedium& );
104
105
    virtual void        Draw(OutputDevice *pDevice,
106
                             const JobSetup & rSetup,
107
                             sal_uInt16 nAspect,
108
                             bool bOutputForScreen) override;
109
110
    virtual void        FillClass(SvGlobalName* pClassName,
111
                                  SotClipboardFormatId*  pFormat,
112
                                  OUString* pFullTypeName,
113
                                  sal_Int32 nFileFormat,
114
                                  bool bTemplate = false ) const override;
115
116
    virtual void        OnDocumentPrinterChanged( Printer * ) override;
117
    virtual bool        InitNew( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
118
    virtual bool        Load( SfxMedium& rMedium ) override;
119
    virtual bool        Save() override;
120
    virtual bool        SaveAs( SfxMedium& rMedium ) override;
121
122
    Printer             *GetPrt();
123
    OutputDevice*       GetRefDev();
124
125
24.6k
    void                SetFormulaArranged(bool bVal) { mbFormulaArranged = bVal; }
126
127
    virtual bool        ConvertFrom(SfxMedium &rMedium) override;
128
129
    /** Called whenever the formula is changed
130
     * Deletes the current cursor
131
     */
132
    void                InvalidateCursor();
133
134
public:
135
    SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+SfxInterfaceId(1))
136
137
    SFX_DECL_OBJECTFACTORY();
138
139
private:
140
    /// SfxInterface initializer.
141
    static void InitInterface_Impl();
142
143
public:
144
    explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags );
145
    virtual     ~SmDocShell() override;
146
147
    virtual bool        ConvertTo( SfxMedium &rMedium ) override;
148
149
    // For unit tests, not intended to use in other context
150
0
    void SetGreekCharStyle(sal_Int16 nVal) { maFormat.SetGreekCharStyle(nVal); }
151
152
    static void LoadSymbols();
153
    static void SaveSymbols();
154
155
    void        ArrangeFormula();
156
157
    //Access for the View. This access is not for the OLE-case!
158
    //and for the communication with the SFX!
159
    //All internal printer uses should work with the SmPrinterAccess only
160
0
    bool        HasPrinter() const { return mpPrinter != nullptr; }
161
0
    SfxPrinter *GetPrinter()    { GetPrt(); return mpPrinter; }
162
    void        SetPrinter( SfxPrinter * );
163
164
    OUString GetComment() const;
165
166
    // to replace chars that can not be saved with the document...
167
    void        ReplaceBadChars();
168
169
    void        UpdateText();
170
    void        SetText(const OUString& rBuffer);
171
0
    const OUString&  GetText() const { return maText; }
172
    void        SetFormat(SmFormat const & rFormat);
173
10.7k
    const SmFormat&  GetFormat() const { return maFormat; }
174
175
    void            Parse();
176
5.26k
    AbstractSmParser* GetParser() { return maParser.get(); }
177
0
    const SmTableNode *GetFormulaTree() const  { return mpTree.get(); }
178
5.26k
    void            SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); }
179
0
    sal_Int16       GetSmSyntaxVersion() const { return mnSmSyntaxVersion; }
180
    void            SetSmSyntaxVersion(sal_Int16 nSmSyntaxVersion);
181
182
0
    const std::set< OUString > &    GetUsedSymbols() const  { return maUsedSymbols; }
183
184
    OUString const & GetAccessibleText();
185
186
    EditEngine &    GetEditEngine();
187
188
    void        DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSelection = false);
189
    Size        GetSize();
190
191
    void        Repaint();
192
193
    virtual SfxUndoManager *GetUndoManager () override;
194
195
    static SfxItemPool& GetPool();
196
197
    void        Execute( SfxRequest& rReq );
198
    void        GetState(SfxItemSet &);
199
200
    virtual void SetVisArea (const tools::Rectangle & rVisArea) override;
201
    virtual void SetModified(bool bModified = true) override;
202
203
    /** Get a cursor for modifying this document
204
     * @remarks Don't store this reference, a new cursor may be made...
205
     */
206
    SmCursor&   GetCursor();
207
    /** True, if cursor have previously been requested and thus
208
     * has some sort of position.
209
     */
210
    bool        HasCursor() const;
211
212
    void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr& pSerializer,
213
            oox::core::OoxmlVersion version,
214
            oox::drawingml::DocumentType documentType,
215
            const sal_Int8 nAlign);
216
    void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding);
217
    void readFormulaOoxml( oox::formulaimport::XmlStream& stream );
218
219
    void UpdateEditEngineDefaultFonts();
220
221
0
    SmMlElement* GetMlElementTree()  { return m_pMlElementTree; }
222
0
    void SetMlElementTree(SmMlElement* pMlElementTree) {
223
0
        mathml::SmMlIteratorFree(m_pMlElementTree);
224
0
        m_pMlElementTree = pMlElementTree;
225
0
    }
226
227
    void SetRightToLeft(bool bRTL);
228
229
    void Impl_Print(OutputDevice& rOutDev, const SmPrintUIOptions& rPrintUIOptions,
230
                    tools::Rectangle aOutRect);
231
};
232
233
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */