Bump version to 21.06.18.1
[LibreOffice.git] / starmath / inc / document.hxx
blob1b425c91e7d1b7ffaa8aa47bebc63f2f7e0661ec
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 #ifndef INCLUDED_STARMATH_INC_DOCUMENT_HXX
21 #define INCLUDED_STARMATH_INC_DOCUMENT_HXX
23 #include <rtl/ustring.hxx>
24 #include <rtl/strbuf.hxx>
25 #include <sfx2/docfac.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <svl/lstner.hxx>
28 #include <sax/fshelper.hxx>
29 #include <unotools/lingucfg.hxx>
30 #include <oox/core/filterbase.hxx>
31 #include <oox/export/utils.hxx>
33 #include <memory>
34 #include <set>
36 #include "format.hxx"
37 #include "node.hxx"
38 #include "parse.hxx"
39 #include "smdllapi.hxx"
41 class SfxPrinter;
42 class Printer;
43 class SmCursor;
45 namespace oox::formulaimport { class XmlStream; }
47 #define STAROFFICE_XML "StarOffice XML (Math)"
48 #define MATHML_XML "MathML XML (Math)"
50 /* Access to printer should happen through this class only
51 * ==========================================================================
53 * The printer can belong to the document or the OLE-Container. If the document
54 * is an OLE-Document the printer generally belongs to the container too.
55 * But the container maybe works with a different MapUnit than the server.
56 * Referring to the MapMode the printer will be accordingly adjusted in the
57 * constructor and restored in the destructor. This brings that this class
58 * is always allowed to exists only a short time (e.g. while painting).
59 * The control whether the printer is self-generated, gotten from the server
60 * or is NULL then, is taken by the DocShell in the method GetPrt(), for
61 * which the access is friend of the DocShell too.
64 class SmDocShell;
65 class EditEngine;
67 class SmPrinterAccess
69 VclPtr<Printer> pPrinter;
70 VclPtr<OutputDevice> pRefDev;
71 public:
72 explicit SmPrinterAccess( SmDocShell &rDocShell );
73 ~SmPrinterAccess();
74 Printer* GetPrinter() { return pPrinter.get(); }
75 OutputDevice* GetRefDev() { return pRefDev.get(); }
79 class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener
81 friend class SmPrinterAccess;
82 friend class SmCursor;
84 OUString maText;
85 SmFormat maFormat;
86 SmParser maParser;
87 OUString maAccText;
88 SvtLinguOptions maLinguOptions;
89 std::unique_ptr<SmTableNode> mpTree;
90 SfxItemPool *mpEditEngineItemPool;
91 std::unique_ptr<EditEngine> mpEditEngine;
92 VclPtr<SfxPrinter> mpPrinter; //q.v. comment to SmPrinter Access!
93 VclPtr<Printer> mpTmpPrinter; //ditto
94 sal_uInt16 mnModifyCount;
95 bool mbFormulaArranged;
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) override;
108 virtual void FillClass(SvGlobalName* pClassName,
109 SotClipboardFormatId* pFormat,
110 OUString* pFullTypeName,
111 sal_Int32 nFileFormat,
112 bool bTemplate = false ) const override;
114 virtual void OnDocumentPrinterChanged( Printer * ) override;
115 virtual bool InitNew( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
116 virtual bool Load( SfxMedium& rMedium ) override;
117 virtual bool Save() override;
118 virtual bool SaveAs( SfxMedium& rMedium ) override;
120 Printer *GetPrt();
121 OutputDevice* GetRefDev();
123 void SetFormulaArranged(bool bVal) { mbFormulaArranged = bVal; }
125 virtual bool ConvertFrom(SfxMedium &rMedium) override;
127 /** Called whenever the formula is changed
128 * Deletes the current cursor
130 void InvalidateCursor();
132 public:
133 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+SfxInterfaceId(1))
135 SFX_DECL_OBJECTFACTORY();
137 private:
138 /// SfxInterface initializer.
139 static void InitInterface_Impl();
141 public:
142 explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags );
143 virtual ~SmDocShell() override;
145 virtual bool ConvertTo( SfxMedium &rMedium ) override;
147 // For unit tests, not intended to use in other context
148 void SetGreekCharStyle(sal_Int16 nVal) { maFormat.SetGreekCharStyle(nVal); }
150 static void LoadSymbols();
151 static void SaveSymbols();
153 void ArrangeFormula();
155 //Access for the View. This access is not for the OLE-case!
156 //and for the communication with the SFX!
157 //All internal printer uses should work with the SmPrinterAccess only
158 bool HasPrinter() const { return mpPrinter != nullptr; }
159 SfxPrinter *GetPrinter() { GetPrt(); return mpPrinter; }
160 void SetPrinter( SfxPrinter * );
162 OUString GetComment() const;
164 // to replace chars that can not be saved with the document...
165 void ReplaceBadChars();
167 void UpdateText();
168 void SetText(const OUString& rBuffer);
169 const OUString& GetText() const { return maText; }
170 void SetFormat(SmFormat const & rFormat);
171 const SmFormat& GetFormat() const { return maFormat; }
173 void Parse();
174 SmParser & GetParser() { return maParser; }
175 const SmTableNode *GetFormulaTree() const { return mpTree.get(); }
176 void SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); }
178 const std::set< OUString > & GetUsedSymbols() const { return maUsedSymbols; }
180 OUString const & GetAccessibleText();
182 EditEngine & GetEditEngine();
184 void DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSelection = false);
185 Size GetSize();
187 void Repaint();
189 virtual SfxUndoManager *GetUndoManager () override;
191 static SfxItemPool& GetPool();
193 void Execute( SfxRequest& rReq );
194 void GetState(SfxItemSet &);
196 virtual void SetVisArea (const tools::Rectangle & rVisArea) override;
197 virtual void SetModified(bool bModified = true) override;
199 /** Get a cursor for modifying this document
200 * @remarks Don't store this reference, a new cursor may be made...
202 SmCursor& GetCursor();
203 /** True, if cursor have previously been requested and thus
204 * has some sort of position.
206 bool HasCursor() const;
208 void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr& pSerializer,
209 oox::core::OoxmlVersion version,
210 oox::drawingml::DocumentType documentType,
211 const sal_Int8 nAlign);
212 void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding);
213 void readFormulaOoxml( oox::formulaimport::XmlStream& stream );
215 void UpdateEditEngineDefaultFonts(const Color& aTextColor);
218 #endif
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */