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 #ifndef INCLUDED_STARMATH_INC_DOCUMENT_HXX 21 #define INCLUDED_STARMATH_INC_DOCUMENT_HXX 22 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> 32 33 #include <memory> 34 #include <set> 35 36 #include "format.hxx" 37 #include "node.hxx" 38 #include "parse.hxx" 39 #include "smdllapi.hxx" 40 41 class SfxPrinter; 42 class Printer; 43 class SmCursor; 44 45 namespace oox { namespace formulaimport { class XmlStream; } } 46 47 #define STAROFFICE_XML "StarOffice XML (Math)" 48 #define MATHML_XML "MathML XML (Math)" 49 50 /* Access to printer should happen through this class only 51 * ========================================================================== 52 * 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. 62 */ 63 64 class SmDocShell; 65 class EditEngine; 66 67 class SmPrinterAccess 68 { 69 VclPtr<Printer> pPrinter; 70 VclPtr<OutputDevice> pRefDev; 71 public: 72 explicit SmPrinterAccess( SmDocShell &rDocShell ); 73 ~SmPrinterAccess(); GetPrinter()74 Printer* GetPrinter() { return pPrinter.get(); } GetRefDev()75 OutputDevice* GetRefDev() { return pRefDev.get(); } 76 }; 77 78 79 class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener 80 { 81 friend class SmPrinterAccess; 82 friend class SmCursor; 83 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 98 99 100 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override; 101 102 bool WriteAsMathType3( SfxMedium& ); 103 104 virtual void Draw(OutputDevice *pDevice, 105 const JobSetup & rSetup, 106 sal_uInt16 nAspect) override; 107 108 virtual void FillClass(SvGlobalName* pClassName, 109 SotClipboardFormatId* pFormat, 110 OUString* pFullTypeName, 111 sal_Int32 nFileFormat, 112 bool bTemplate = false ) const override; 113 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; 119 120 Printer *GetPrt(); 121 OutputDevice* GetRefDev(); 122 SetFormulaArranged(bool bVal)123 void SetFormulaArranged(bool bVal) { mbFormulaArranged = bVal; } 124 125 virtual bool ConvertFrom(SfxMedium &rMedium) override; 126 127 /** Called whenever the formula is changed 128 * Deletes the current cursor 129 */ 130 void InvalidateCursor(); 131 132 public: 133 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+SfxInterfaceId(1)) 134 135 SFX_DECL_OBJECTFACTORY(); 136 137 private: 138 /// SfxInterface initializer. 139 static void InitInterface_Impl(); 140 141 public: 142 explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags ); 143 virtual ~SmDocShell() override; 144 145 virtual bool ConvertTo( SfxMedium &rMedium ) override; 146 147 // For unit tests, not intended to use in other context SetGreekCharStyle(sal_Int16 nVal)148 void SetGreekCharStyle(sal_Int16 nVal) { maFormat.SetGreekCharStyle(nVal); } 149 150 static void LoadSymbols(); 151 static void SaveSymbols(); 152 153 void ArrangeFormula(); 154 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 HasPrinter() const158 bool HasPrinter() const { return mpPrinter != nullptr; } GetPrinter()159 SfxPrinter *GetPrinter() { GetPrt(); return mpPrinter; } 160 void SetPrinter( SfxPrinter * ); 161 162 OUString GetComment() const; 163 164 // to replace chars that can not be saved with the document... 165 void ReplaceBadChars(); 166 167 void UpdateText(); 168 void SetText(const OUString& rBuffer); GetText() const169 const OUString& GetText() const { return maText; } 170 void SetFormat(SmFormat const & rFormat); GetFormat() const171 const SmFormat& GetFormat() const { return maFormat; } 172 173 void Parse(); GetParser()174 SmParser & GetParser() { return maParser; } GetFormulaTree() const175 const SmTableNode *GetFormulaTree() const { return mpTree.get(); } SetFormulaTree(SmTableNode * pTree)176 void SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); } 177 GetUsedSymbols() const178 const std::set< OUString > & GetUsedSymbols() const { return maUsedSymbols; } 179 180 OUString const & GetAccessibleText(); 181 182 EditEngine & GetEditEngine(); 183 184 void DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSelection = false); 185 Size GetSize(); 186 187 void Repaint(); 188 189 virtual SfxUndoManager *GetUndoManager () override; 190 191 static SfxItemPool& GetPool(); 192 193 void Execute( SfxRequest& rReq ); 194 void GetState(SfxItemSet &); 195 196 virtual void SetVisArea (const tools::Rectangle & rVisArea) override; 197 virtual void SetModified(bool bModified = true) override; 198 199 /** Get a cursor for modifying this document 200 * @remarks Don't store this reference, a new cursor may be made... 201 */ 202 SmCursor& GetCursor(); 203 /** True, if cursor have previously been requested and thus 204 * has some sort of position. 205 */ 206 bool HasCursor() const; 207 208 void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr& pSerializer, 209 oox::core::OoxmlVersion version, 210 oox::drawingml::DocumentType documentType); 211 void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding); 212 void readFormulaOoxml( oox::formulaimport::XmlStream& stream ); 213 214 void UpdateEditEngineDefaultFonts(const Color& aTextColor); 215 }; 216 217 #endif 218 219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 220