Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / starmath / inc / document.hxx
blobbf9477b30f1134246d02e174db24719d7695ab6a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
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>
32 #include "format.hxx"
33 #include "node.hxx"
34 #include "parsebase.hxx"
35 #include "smdllapi.hxx"
36 #include "mathml/iterator.hxx"
38 class SfxPrinter;
39 class Printer;
40 class SmCursor;
42 namespace oox::formulaimport { class XmlStream; }
44 #define STAROFFICE_XML "StarOffice XML (Math)"
45 inline constexpr OUStringLiteral MATHML_XML = u"MathML XML (Math)";
47 /* Access to printer should happen through this class only
48 * ==========================================================================
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.
61 class SmDocShell;
62 class EditEngine;
63 class SmEditEngine;
65 class SmPrinterAccess
67 VclPtr<Printer> pPrinter;
68 VclPtr<OutputDevice> pRefDev;
69 public:
70 explicit SmPrinterAccess( SmDocShell &rDocShell );
71 ~SmPrinterAccess();
72 Printer* GetPrinter() { return pPrinter.get(); }
73 OutputDevice* GetRefDev() { return pRefDev.get(); }
77 class SM_DLLPUBLIC SmDocShell final : public SfxObjectShell, public SfxListener
79 friend class SmPrinterAccess;
80 friend class SmCursor;
82 OUString maText;
83 SmFormat maFormat;
84 OUString maAccText;
85 SvtLinguOptions maLinguOptions;
86 std::unique_ptr<SmTableNode> mpTree;
87 SmMlElement* m_pMlElementTree;
88 rtl::Reference<SfxItemPool> mpEditEngineItemPool;
89 std::unique_ptr<SmEditEngine> mpEditEngine;
90 VclPtr<SfxPrinter> mpPrinter; //q.v. comment to SmPrinter Access!
91 VclPtr<Printer> mpTmpPrinter; //ditto
92 sal_uInt16 mnModifyCount;
93 bool mbFormulaArranged;
94 sal_uInt16 mnSmSyntaxVersion;
95 std::unique_ptr<AbstractSmParser> maParser;
96 std::unique_ptr<SmCursor> mpCursor;
97 std::set< OUString > maUsedSymbols; // to export used symbols only when saving
100 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
102 bool WriteAsMathType3( SfxMedium& );
104 virtual void Draw(OutputDevice *pDevice,
105 const JobSetup & rSetup,
106 sal_uInt16 nAspect,
107 bool bOutputForScreen) override;
109 virtual void FillClass(SvGlobalName* pClassName,
110 SotClipboardFormatId* pFormat,
111 OUString* pFullTypeName,
112 sal_Int32 nFileFormat,
113 bool bTemplate = false ) const override;
115 virtual void OnDocumentPrinterChanged( Printer * ) override;
116 virtual bool InitNew( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
117 virtual bool Load( SfxMedium& rMedium ) override;
118 virtual bool Save() override;
119 virtual bool SaveAs( SfxMedium& rMedium ) override;
121 Printer *GetPrt();
122 OutputDevice* GetRefDev();
124 void SetFormulaArranged(bool bVal) { mbFormulaArranged = bVal; }
126 virtual bool ConvertFrom(SfxMedium &rMedium) override;
128 /** Called whenever the formula is changed
129 * Deletes the current cursor
131 void InvalidateCursor();
133 public:
134 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+SfxInterfaceId(1))
136 SFX_DECL_OBJECTFACTORY();
138 private:
139 /// SfxInterface initializer.
140 static void InitInterface_Impl();
142 public:
143 explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags );
144 virtual ~SmDocShell() override;
146 virtual bool ConvertTo( SfxMedium &rMedium ) override;
148 // For unit tests, not intended to use in other context
149 void SetGreekCharStyle(sal_Int16 nVal) { maFormat.SetGreekCharStyle(nVal); }
151 static void LoadSymbols();
152 static void SaveSymbols();
154 void ArrangeFormula();
156 //Access for the View. This access is not for the OLE-case!
157 //and for the communication with the SFX!
158 //All internal printer uses should work with the SmPrinterAccess only
159 bool HasPrinter() const { return mpPrinter != nullptr; }
160 SfxPrinter *GetPrinter() { GetPrt(); return mpPrinter; }
161 void SetPrinter( SfxPrinter * );
163 OUString GetComment() const;
165 // to replace chars that can not be saved with the document...
166 void ReplaceBadChars();
168 void UpdateText();
169 void SetText(const OUString& rBuffer);
170 const OUString& GetText() const { return maText; }
171 void SetFormat(SmFormat const & rFormat);
172 const SmFormat& GetFormat() const { return maFormat; }
174 void Parse();
175 AbstractSmParser* GetParser() { return maParser.get(); }
176 const SmTableNode *GetFormulaTree() const { return mpTree.get(); }
177 void SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); }
178 sal_uInt16 GetSmSyntaxVersion() const { return mnSmSyntaxVersion; }
179 void SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion);
181 const std::set< OUString > & GetUsedSymbols() const { return maUsedSymbols; }
183 OUString const & GetAccessibleText();
185 EditEngine & GetEditEngine();
187 void DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSelection = false);
188 Size GetSize();
190 void Repaint();
192 virtual SfxUndoManager *GetUndoManager () override;
194 static SfxItemPool& GetPool();
196 void Execute( SfxRequest& rReq );
197 void GetState(SfxItemSet &);
199 virtual void SetVisArea (const tools::Rectangle & rVisArea) override;
200 virtual void SetModified(bool bModified = true) override;
202 /** Get a cursor for modifying this document
203 * @remarks Don't store this reference, a new cursor may be made...
205 SmCursor& GetCursor();
206 /** True, if cursor have previously been requested and thus
207 * has some sort of position.
209 bool HasCursor() const;
211 void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr& pSerializer,
212 oox::core::OoxmlVersion version,
213 oox::drawingml::DocumentType documentType,
214 const sal_Int8 nAlign);
215 void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding);
216 void readFormulaOoxml( oox::formulaimport::XmlStream& stream );
218 void UpdateEditEngineDefaultFonts();
220 SmMlElement* GetMlElementTree() { return m_pMlElementTree; }
221 void SetMlElementTree(SmMlElement* pMlElementTree) {
222 mathml::SmMlIteratorFree(m_pMlElementTree);
223 m_pMlElementTree = pMlElementTree;
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */