1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sot/storage.hxx>
28 #include <svl/lstner.hxx>
29 #include <vcl/jobset.hxx>
30 #include <vcl/virdev.hxx>
31 #include <sax/fshelper.hxx>
32 #include <unotools/lingucfg.hxx>
33 #include <oox/core/filterbase.hxx>
34 #include <oox/mathml/import.hxx>
35 #include <oox/export/utils.hxx>
43 #include "smdllapi.hxx"
49 #define STAROFFICE_XML "StarOffice XML (Math)"
50 #define MATHML_XML "MathML XML (Math)"
52 /* Access to printer should happen through this class only
53 * ==========================================================================
55 * The printer can belong to the document or the OLE-Container. If the document
56 * is an OLE-Document the printer generally belongs to the container too.
57 * But the container maybe works with a different MapUnit than the server.
58 * Referring to the MapMode the printer will be accordingly adjusted in the
59 * constructor and restored in the destructor. This brings that this class
60 * is always allowed to exists only a short time (e.g. while painting).
61 * The control whether the printer is self-generated, gotten from the server
62 * or is NULL then, is taken by the DocShell in the method GetPrt(), for
63 * which the access is friend of the DocShell too.
71 VclPtr
<Printer
> pPrinter
;
72 VclPtr
<OutputDevice
> pRefDev
;
74 explicit SmPrinterAccess( SmDocShell
&rDocShell
);
76 Printer
* GetPrinter() { return pPrinter
.get(); }
77 OutputDevice
* GetRefDev() { return pRefDev
.get(); }
80 void SetEditEngineDefaultFonts(SfxItemPool
&rEditEngineItemPool
, const SvtLinguOptions
&rOpt
);
82 class SM_DLLPUBLIC SmDocShell
: public SfxObjectShell
, public SfxListener
84 friend class SmPrinterAccess
;
85 friend class SmCursor
;
91 SvtLinguOptions maLinguOptions
;
92 std::unique_ptr
<SmTableNode
> mpTree
;
93 SfxItemPool
*mpEditEngineItemPool
;
94 std::unique_ptr
<EditEngine
> mpEditEngine
;
95 VclPtr
<SfxPrinter
> mpPrinter
; //q.v. comment to SmPrinter Access!
96 VclPtr
<Printer
> mpTmpPrinter
; //ditto
97 sal_uInt16 mnModifyCount
;
98 bool mbFormulaArranged
;
99 std::unique_ptr
<SmCursor
> mpCursor
;
100 std::set
< OUString
> maUsedSymbols
; // to export used symbols only when saving
103 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
105 bool WriteAsMathType3( SfxMedium
& );
107 virtual void Draw(OutputDevice
*pDevice
,
108 const JobSetup
& rSetup
,
109 sal_uInt16 nAspect
) override
;
111 virtual void FillClass(SvGlobalName
* pClassName
,
112 SotClipboardFormatId
* pFormat
,
114 OUString
* pFullTypeName
,
115 OUString
* pShortTypeName
,
116 sal_Int32 nFileFormat
,
117 bool bTemplate
= false ) const override
;
119 virtual void OnDocumentPrinterChanged( Printer
* ) override
;
120 virtual bool InitNew( const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
121 virtual bool Load( SfxMedium
& rMedium
) override
;
122 virtual bool Save() override
;
123 virtual bool SaveAs( SfxMedium
& rMedium
) override
;
126 OutputDevice
* GetRefDev();
128 void SetFormulaArranged(bool bVal
) { mbFormulaArranged
= bVal
; }
130 virtual bool ConvertFrom(SfxMedium
&rMedium
) override
;
132 /** Called whenever the formula is changed
133 * Deletes the current cursor
135 void InvalidateCursor();
138 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START
+SfxInterfaceId(1))
140 SFX_DECL_OBJECTFACTORY();
143 /// SfxInterface initializer.
144 static void InitInterface_Impl();
147 explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags
);
148 virtual ~SmDocShell() override
;
150 virtual bool ConvertTo( SfxMedium
&rMedium
) override
;
152 // For unit tests, not intended to use in other context
153 void SetGreekCharStyle(sal_Int16 nVal
) { maFormat
.SetGreekCharStyle(nVal
); }
155 static void LoadSymbols();
156 static void SaveSymbols();
158 void ArrangeFormula();
160 //Access for the View. This access is not for the OLE-case!
161 //and for the communication with the SFX!
162 //All internal printer uses should work with the SmPrinterAccess only
163 bool HasPrinter() { return mpPrinter
!= nullptr; }
164 SfxPrinter
*GetPrinter() { GetPrt(); return mpPrinter
; }
165 void SetPrinter( SfxPrinter
* );
167 const OUString
GetComment() const;
169 // to replace chars that can not be saved with the document...
170 void ReplaceBadChars();
173 void SetText(const OUString
& rBuffer
);
174 const OUString
& GetText() { return maText
; }
175 void SetFormat(SmFormat
const & rFormat
);
176 const SmFormat
& GetFormat() { return maFormat
; }
179 SmParser
& GetParser() { return maParser
; }
180 const SmTableNode
*GetFormulaTree() const { return mpTree
.get(); }
181 void SetFormulaTree(SmTableNode
*pTree
) { mpTree
.reset(pTree
); }
183 const std::set
< OUString
> & GetUsedSymbols() const { return maUsedSymbols
; }
185 OUString
const & GetAccessibleText();
187 EditEngine
& GetEditEngine();
188 SfxItemPool
& GetEditEngineItemPool();
189 const SvtLinguOptions
& GetLinguOptions() const { return maLinguOptions
; }
191 void DrawFormula(OutputDevice
&rDev
, Point
&rPosition
, bool bDrawSelection
= false);
196 virtual ::svl::IUndoManager
*GetUndoManager () override
;
198 static SfxItemPool
& GetPool();
200 void Execute( SfxRequest
& rReq
);
201 void GetState(SfxItemSet
&);
203 virtual void SetVisArea (const tools::Rectangle
& rVisArea
) override
;
204 virtual void SetModified(bool bModified
= true) override
;
206 /** Get a cursor for modifying this document
207 * @remarks Don't store this reference, a new cursor may be made...
209 SmCursor
& GetCursor();
210 /** True, if cursor have previously been requested and thus
211 * has some sort of position.
215 void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr
& pSerializer
,
216 oox::core::OoxmlVersion version
,
217 oox::drawingml::DocumentType documentType
);
218 void writeFormulaRtf(OStringBuffer
& rBuffer
, rtl_TextEncoding nEncoding
);
219 void readFormulaOoxml( oox::formulaimport::XmlStream
& stream
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */