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 .
25 #include <rtl/ustring.hxx>
26 #include <rtl/strbuf.hxx>
27 #include <sfx2/docfac.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sot/storage.hxx>
30 #include <svl/lstner.hxx>
31 #include <vcl/jobset.hxx>
32 #include <vcl/virdev.hxx>
33 #include <sax/fshelper.hxx>
34 #include <oox/core/filterbase.hxx>
35 #include <oox/mathml/import.hxx>
44 class SfxMenuBarManager
;
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 mayby 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.
69 ////////////////////////////////////////////////////////////
74 OutputDevice
* pRefDev
;
76 SmPrinterAccess( SmDocShell
&rDocShell
);
78 Printer
* GetPrinter() { return pPrinter
; }
79 OutputDevice
* GetRefDev() { return pRefDev
; }
83 ////////////////////////////////////////////////////////////
85 void SetEditEngineDefaultFonts(SfxItemPool
&rEditEngineItemPool
);
87 ////////////////////////////////////////////////////////////
89 class SmDocShell
: public SfxObjectShell
, public SfxListener
91 friend class SmPrinterAccess
;
93 friend class SmCursor
;
97 SmParser aInterpreter
;
100 SfxMenuBarManager
*pMenuMgr
;
101 SfxItemPool
*pEditEngineItemPool
;
102 EditEngine
*pEditEngine
;
103 SfxPrinter
*pPrinter
; //q.v. comment to SmPrinter Access!
104 Printer
*pTmpPrinter
; //ditto
109 sal_uInt16 nModifyCount
;
110 bool bIsFormulaArranged
;
112 std::set
< OUString
> aUsedSymbols
; // to export used symbols only when saving
116 virtual void SFX_NOTIFY(SfxBroadcaster
& rBC
, const TypeId
& rBCType
,
117 const SfxHint
& rHint
, const TypeId
& rHintType
);
119 bool WriteAsMathType3( SfxMedium
& );
121 virtual void Draw(OutputDevice
*pDevice
,
122 const JobSetup
& rSetup
,
123 sal_uInt16 nAspect
= ASPECT_CONTENT
);
125 virtual void FillClass(SvGlobalName
* pClassName
,
128 OUString
* pFullTypeName
,
129 OUString
* pShortTypeName
,
130 sal_Int32 nFileFormat
,
131 sal_Bool bTemplate
= sal_False
) const;
133 virtual sal_Bool
SetData( const String
& rData
);
134 virtual sal_uLong
GetMiscStatus() const;
135 virtual void OnDocumentPrinterChanged( Printer
* );
136 virtual sal_Bool
InitNew( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
);
137 virtual sal_Bool
Load( SfxMedium
& rMedium
);
138 void ImplSave( SvStorageStreamRef xStrm
);
139 virtual sal_Bool
Save();
140 virtual sal_Bool
SaveAs( SfxMedium
& rMedium
);
141 virtual sal_Bool
ConvertTo( SfxMedium
&rMedium
);
142 virtual sal_Bool
SaveCompleted( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
);
145 OutputDevice
* GetRefDev();
147 bool IsFormulaArranged() const { return bIsFormulaArranged
; }
148 void SetFormulaArranged(bool bVal
) { bIsFormulaArranged
= bVal
; }
150 virtual sal_Bool
ConvertFrom(SfxMedium
&rMedium
);
152 /** Called whenever the formula is changed
153 * Deletes the current cursor
155 void InvalidateCursor();
157 bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr pSerializer
, oox::core::OoxmlVersion version
);
158 void writeFormulaRtf(OStringBuffer
& rBuffer
, rtl_TextEncoding nEncoding
);
159 void readFormulaOoxml( oox::formulaimport::XmlStream
& stream
);
163 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START
+1)
164 using SotObject::GetInterface
;
165 SFX_DECL_OBJECTFACTORY();
167 SmDocShell( const sal_uInt64 i_nSfxCreationFlags
);
168 virtual ~SmDocShell();
173 void ArrangeFormula();
175 //Access for the View. This access is not for the OLE-case!
176 //and for the communication with the SFX!
177 //All internal printer uses should work with the SmPrinterAccess only
178 bool HasPrinter() { return 0 != pPrinter
; }
179 SfxPrinter
*GetPrinter() { GetPrt(); return pPrinter
; }
180 void SetPrinter( SfxPrinter
* );
182 const String
GetComment() const;
184 // to replace chars that can not be saved with the document...
185 sal_Bool
ReplaceBadChars();
188 void SetText(const OUString
& rBuffer
);
189 OUString
GetText() { return (OUString(aText
)); }
190 void SetFormat(SmFormat
& rFormat
);
191 const SmFormat
& GetFormat() { return (aFormat
); }
194 SmParser
& GetParser() { return aInterpreter
; }
195 const SmNode
* GetFormulaTree() const { return pTree
; }
196 void SetFormulaTree(SmNode
*&rTree
) { pTree
= rTree
; }
198 const std::set
< OUString
> & GetUsedSymbols() const { return aUsedSymbols
; }
200 OUString
GetAccessibleText();
202 EditEngine
& GetEditEngine();
203 SfxItemPool
& GetEditEngineItemPool();
205 void DrawFormula(OutputDevice
&rDev
, Point
&rPosition
, bool bDrawSelection
= false);
210 virtual ::svl::IUndoManager
*GetUndoManager ();
212 virtual SfxItemPool
& GetPool() const;
214 void Execute( SfxRequest
& rReq
);
215 void GetState(SfxItemSet
&);
217 virtual void SetVisArea (const Rectangle
& rVisArea
);
218 virtual void SetModified(sal_Bool bModified
);
220 /** Get a cursor for modifying this document
221 * @remarks Don't store this reference, a new cursor may be made...
223 SmCursor
& GetCursor();
224 /** True, if cursor have previously been requested and thus
225 * has some sort of position.
227 bool HasCursor() { return pCursor
!= NULL
; }
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */