document.hxx 8.11 KB
Newer Older
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
Júlio Hoffimann's avatar
Júlio Hoffimann committed
19

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
20 21 22 23 24
#ifndef DOCUMENT_HXX
#define DOCUMENT_HXX

#define SMDLL   1

25
#include <rtl/ustring.hxx>
26
#include <rtl/strbuf.hxx>
27
#include <sfx2/docfac.hxx>
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
28
#include <sfx2/objsh.hxx>
29
#include <sot/storage.hxx>
30
#include <svl/lstner.hxx>
31
#include <vcl/jobset.hxx>
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
32
#include <vcl/virdev.hxx>
33
#include <sax/fshelper.hxx>
34
#include <oox/core/filterbase.hxx>
35
#include <oox/mathml/import.hxx>
36

37 38
#include <set>

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
39 40 41 42 43
#include "format.hxx"
#include "parse.hxx"
#include "smmod.hxx"

class SmNode;
44
class SfxMenuBarManager;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
45 46
class SfxPrinter;
class Printer;
47
class SmCursor;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
48

49 50 51
#define STAROFFICE_XML  "StarOffice XML (Math)"
#define MATHML_XML      "MathML XML (Math)"

52
/* Access to printer should happen through this class only
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
53 54
 * ==========================================================================
 *
55 56 57 58 59 60 61 62 63 64
 * The printer can belong to the document or the OLE-Container. If the document
 * is an OLE-Document the printer generally belongs to the container too.
 * But the container mayby works with a different MapUnit than the server.
 * Referring to the MapMode the printer will be accordingly adjusted in the
 * constructor and restored in the destructor. This brings that this class
 * is always allowed to exists only a short time (e.g. while painting).
 * The control whether the printer is self-generated, gotten from the server
 * or is NULL then, is taken by the DocShell in the method GetPrt(), for
 * which the access is friend of the DocShell too.
 */
65

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
66
class SmDocShell;
67
class EditEngine;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
68

69 70
////////////////////////////////////////////////////////////

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
71 72
class SmPrinterAccess
{
73 74
    Printer* pPrinter;
    OutputDevice* pRefDev;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
75 76 77
public:
    SmPrinterAccess( SmDocShell &rDocShell );
    ~SmPrinterAccess();
78 79
    Printer* GetPrinter()  { return pPrinter; }
    OutputDevice* GetRefDev()  { return pRefDev; }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
80 81 82
};


83 84
////////////////////////////////////////////////////////////

85
void SetEditEngineDefaultFonts(SfxItemPool &rEditEngineItemPool);
86

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
87 88
////////////////////////////////////////////////////////////

89
class SmDocShell : public SfxObjectShell, public SfxListener
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
90 91
{
    friend class SmPrinterAccess;
92
    friend class SmModel;
93
    friend class SmCursor;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
94 95 96 97

    String              aText;
    SmFormat            aFormat;
    SmParser            aInterpreter;
Ivan Timofeev's avatar
Ivan Timofeev committed
98
    OUString            aAccText;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
99 100
    SmNode             *pTree;
    SfxMenuBarManager  *pMenuMgr;
101 102
    SfxItemPool        *pEditEngineItemPool;
    EditEngine         *pEditEngine;
103 104
    SfxPrinter         *pPrinter;       //q.v. comment to SmPrinter Access!
    Printer            *pTmpPrinter;    //ditto
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
105 106 107 108
    long                nLeftBorder,
                        nRightBorder,
                        nTopBorder,
                        nBottomBorder;
109
    sal_uInt16          nModifyCount;
110
    bool                bIsFormulaArranged;
111
    SmCursor           *pCursor;
112
    std::set< OUString >    aUsedSymbols;   // to export used symbols only when saving
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
113 114 115 116 117 118



    virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
                        const SfxHint& rHint, const TypeId& rHintType);

119
    bool        WriteAsMathType3( SfxMedium& );
120

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
121 122
    virtual void        Draw(OutputDevice *pDevice,
                             const JobSetup & rSetup,
123
                             sal_uInt16 nAspect = ASPECT_CONTENT);
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
124 125

    virtual void        FillClass(SvGlobalName* pClassName,
126
                                  sal_uInt32*  pFormat,
127 128 129
                                  OUString* pAppName,
                                  OUString* pFullTypeName,
                                  OUString* pShortTypeName,
130 131
                                  sal_Int32 nFileFormat,
                                  sal_Bool bTemplate = sal_False ) const;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
132

133 134
    virtual sal_Bool        SetData( const String& rData );
    virtual sal_uLong       GetMiscStatus() const;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
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 );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
138
            void        ImplSave(  SvStorageStreamRef xStrm  );
139 140 141 142
    virtual sal_Bool        Save();
    virtual sal_Bool        SaveAs( SfxMedium& rMedium );
    virtual sal_Bool        ConvertTo( SfxMedium &rMedium );
    virtual sal_Bool        SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
143

144 145
    Printer             *GetPrt();
    OutputDevice*       GetRefDev();
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
146

147 148
    bool                IsFormulaArranged() const { return bIsFormulaArranged; }
    void                SetFormulaArranged(bool bVal) { bIsFormulaArranged = bVal; }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
149

150
    virtual sal_Bool        ConvertFrom(SfxMedium &rMedium);
151

152 153 154 155 156
    /** Called whenever the formula is changed
     * Deletes the current cursor
     */
    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 );
160

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
161 162
public:
    TYPEINFO();
163 164
    SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+1)
    using SotObject::GetInterface;
165
    SFX_DECL_OBJECTFACTORY();
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
166

167
                SmDocShell( const sal_uInt64 i_nSfxCreationFlags );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
168 169 170 171 172
    virtual     ~SmDocShell();

    void        LoadSymbols();
    void        SaveSymbols();

173 174
    void        ArrangeFormula();

175 176 177
    //Access for the View. This access is not for the OLE-case!
    //and for the communication with the SFX!
    //All internal printer uses should work with the SmPrinterAccess only
178
    bool        HasPrinter()    { return 0 != pPrinter; }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
179 180 181
    SfxPrinter *GetPrinter()    { GetPrt(); return pPrinter; }
    void        SetPrinter( SfxPrinter * );

182
    const String GetComment() const;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
183

184 185 186
    // to replace chars that can not be saved with the document...
    sal_Bool    ReplaceBadChars();

187
    void        UpdateText();
188 189
    void        SetText(const OUString& rBuffer);
    OUString    GetText() { return (OUString(aText)); }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
190
    void        SetFormat(SmFormat& rFormat);
191
    const SmFormat&  GetFormat() { return (aFormat); }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
192 193 194 195

    void            Parse();
    SmParser &      GetParser() { return aInterpreter; }
    const SmNode *  GetFormulaTree() const  { return pTree; }
196 197
    void            SetFormulaTree(SmNode *&rTree) { pTree = rTree; }

198
    const std::set< OUString > &    GetUsedSymbols() const  { return aUsedSymbols; }
199

Ivan Timofeev's avatar
Ivan Timofeev committed
200
    OUString        GetAccessibleText();
201

202 203
    EditEngine &    GetEditEngine();
    SfxItemPool &   GetEditEngineItemPool();
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
204

205
    void        DrawFormula(OutputDevice &rDev, Point &rPosition, bool bDrawSelection = false);
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
206 207
    Size        GetSize();

208
    void        Repaint();
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
209

210
    virtual     ::svl::IUndoManager *GetUndoManager ();
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
211

212
    virtual     SfxItemPool& GetPool() const;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
213 214 215 216 217

    void        Execute( SfxRequest& rReq );
    void        GetState(SfxItemSet &);

    virtual void SetVisArea (const Rectangle & rVisArea);
218
    virtual void SetModified(sal_Bool bModified);
219 220 221 222 223 224 225 226

    /** Get a cursor for modifying this document
     * @remarks Don't store this reference, a new cursor may be made...
     */
    SmCursor&   GetCursor();
    /** True, if cursor have previously been requested and thus
     * has some sort of position.
     */
227
    bool        HasCursor() { return pCursor != NULL; }
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
228 229 230 231
};

#endif

232
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */