xref: /core/include/sfx2/lnkbase.hxx (revision 3de6d4d3)
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 #pragma once
21 
22 #include <rtl/ustring.hxx>
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sfx2/linksrc.hxx>
26 #include <sot/formats.hxx>
27 #include <tools/ref.hxx>
28 #include <tools/link.hxx>
29 #include <memory>
30 
31 namespace com::sun::star::uno
32 {
33     class Any;
34 }
35 
36 namespace com::sun::star::io { class XInputStream; }
37 
38 enum class SfxLinkUpdateMode {
39     NONE   = 0,
40     // Ole2 compatible and persistent
41     ALWAYS = 1,
42     ONCALL = 3
43 };
44 
45 namespace sfx2
46 {
47 
48 struct ImplBaseLinkData;
49 class LinkManager;
50 class FileDialogHelper;
51 
52 enum class SvBaseLinkObjectType {
53     Internal      = 0x00,
54     DdeExternal   = 0x02,
55     ClientSo      = 0x80, // a Link
56     ClientDde     = 0x81,
57     ClientFile    = 0x90,
58     ClientGraphic = 0x91,
59     ClientOle     = 0x92 // embedded link
60 };
61 
isClientType(SvBaseLinkObjectType t)62 constexpr bool isClientType(SvBaseLinkObjectType t)
63 {
64     return static_cast<int>(t) & static_cast<int>(SvBaseLinkObjectType::ClientSo);
65 }
isClientFileType(SvBaseLinkObjectType t)66 constexpr bool isClientFileType(SvBaseLinkObjectType t)
67 {
68     auto check = static_cast<int>(SvBaseLinkObjectType::ClientFile);
69     return (static_cast<int>(t) & check) == check;
70 }
71 
72 class SFX2_DLLPUBLIC SvBaseLink : public SvRefBase
73 {
74 private:
75     friend class LinkManager;
76     friend class SvLinkSource;
77 
78     Link<SvBaseLink&,void>  m_aEndEditLink;
79     LinkManager*            m_pLinkMgr;
80     weld::Window*           m_pParentWin;
81     std::unique_ptr<FileDialogHelper>
82                             m_pFileDlg;
83     SvLinkSourceRef         xObj;
84     OUString                aLinkName;
85     std::unique_ptr<ImplBaseLinkData> pImplData;
86     SvBaseLinkObjectType    mnObjType;
87     bool                    bVisible : 1;
88     bool                    bSynchron : 1;
89     bool                    bWasLastEditOK : 1;
90     bool                    m_bIsConnect : 1;
91     bool                    m_bIsReadOnly;
92     css::uno::Reference<css::io::XInputStream>
93                             m_xInputStreamToLoadFrom;
94 
95     DECL_DLLPRIVATE_LINK( EndEditHdl, const OUString&, void );
96 
97     bool                    ExecuteEdit( const OUString& _rNewName );
98 
99 protected:
100     void            SetObjType( SvBaseLinkObjectType );
101 
102     // Set LinkSourceName without action
103     void            SetName( const OUString & rLn );
104 
105                     SvBaseLink();
106                     SvBaseLink( SfxLinkUpdateMode nLinkType, SotClipboardFormatId nContentType );
107     virtual         ~SvBaseLink() override;
108 
109     void            GetRealObject_( bool bConnect = true );
110 
GetRealObject()111     SvLinkSource*   GetRealObject()
112                     {
113                         if( !xObj.is() )
114                             GetRealObject_();
115                         return xObj.get();
116                     }
117 
118 public:
119 
120     virtual void    Closed();
121 
122 #if defined(_WIN32)
123                     SvBaseLink( const OUString& rNm, SvBaseLinkObjectType nObjectType,
124                                  SvLinkSource* );
125 #endif
126 
GetObjType() const127     SvBaseLinkObjectType GetObjType() const { return mnObjType; }
128 
129     void            SetObj( SvLinkSource * pObj );
GetObj() const130     SvLinkSource*   GetObj() const  { return xObj.get(); }
131 
132     void            SetLinkSourceName( const OUString & rName );
GetLinkSourceName() const133     const OUString& GetLinkSourceName() const { return aLinkName;}
134 
135     enum UpdateResult {
136         SUCCESS = 0,
137         ERROR_GENERAL = 1
138     };
139 
140     virtual UpdateResult DataChanged(
141         const OUString & rMimeType, const css::uno::Any & rValue );
142 
143     void                 SetUpdateMode( SfxLinkUpdateMode );
144     SfxLinkUpdateMode    GetUpdateMode() const;
145     SotClipboardFormatId GetContentType() const;
146     void                 SetContentType( SotClipboardFormatId nType );
147 
148     LinkManager*          GetLinkManager();
149     const LinkManager*    GetLinkManager() const;
150     void                  SetLinkManager( LinkManager* _pMgr );
151 
152     bool            Update();
153     void            Disconnect();
154 
155     virtual void    Edit(weld::Window*, const Link<SvBaseLink&,void>& rEndEditHdl);
156 
157     // should the link appear in the dialog? (to the left in the link in the...)
IsVisible() const158     bool            IsVisible() const           { return bVisible; }
SetVisible(bool bFlag)159     void            SetVisible( bool bFlag )    { bVisible = bFlag; }
160     // should the Link be loaded synchronous or asynchronous?
IsSynchron() const161     bool            IsSynchron() const          { return bSynchron; }
SetSynchron(bool bFlag)162     void            SetSynchron( bool bFlag )   { bSynchron = bFlag; }
163 
setStreamToLoadFrom(const css::uno::Reference<css::io::XInputStream> & xInputStream,bool bIsReadOnly)164     void            setStreamToLoadFrom(
165                         const css::uno::Reference<css::io::XInputStream>& xInputStream,
166                         bool bIsReadOnly )
167                             { m_xInputStreamToLoadFrom = xInputStream;
168                               m_bIsReadOnly = bIsReadOnly; }
169     // #i88291#
170     void            clearStreamToLoadFrom();
171 
WasLastEditOK() const172     bool     WasLastEditOK() const       { return bWasLastEditOK; }
173     FileDialogHelper & GetInsertFileDialog(const OUString& rFactory);
174 };
175 
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
179