1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _LINKMGR_HXX 24 #define _LINKMGR_HXX 25 26 #include "sal/config.h" 27 #include "sfx2/dllapi.h" 28 #include <sfx2/linksrc.hxx> 29 #include <tools/string.hxx> 30 #include <svl/svarray.hxx> 31 32 class SfxObjectShell; 33 class Graphic; 34 class Size; 35 36 namespace com { namespace sun { namespace star { namespace util { 37 class URL; 38 class XURLTransformer; 39 } } } } 40 41 namespace sfx2 42 { 43 // The FileObject sends a SvData with the FormatId to notify the link about 44 // the status of the to be loaded graphic "RegisterStatusInfoId" and a string 45 // as data carrier. This contains the following enum. 46 47 class SvBaseLink; 48 class SvBaseLinkRef; 49 50 typedef SvBaseLinkRef* SvBaseLinkRefPtr; 51 SV_DECL_PTRARR( SvBaseLinks, SvBaseLinkRefPtr, 1, 1 ) 52 53 typedef SvLinkSource* SvLinkSourcePtr; 54 SV_DECL_PTRARR( SvLinkSources, SvLinkSourcePtr, 1, 1 ) 55 56 class SFX2_DLLPUBLIC LinkManager 57 { 58 SvBaseLinks aLinkTbl; 59 SvLinkSources aServerTbl; 60 61 SfxObjectShell *pPersist; // LinkMgr has to be deallocated before SfxObjectShell 62 63 sal_Bool mAutoAskUpdateAllLinks; 64 sal_Bool mUpdateAsked; 65 sal_Bool mAllowUpdate; 66 67 com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > xURLTransformer; 68 69 void SetUserAllowsLinkUpdate(SvBaseLink *pLink, sal_Bool allows); 70 protected: 71 sal_Bool InsertLink( SvBaseLink* pLink, sal_uInt16 nObjType, sal_uInt16 nUpdateType, 72 const String* pName = 0 ); 73 public: 74 75 enum LinkState 76 { 77 STATE_LOAD_OK, 78 STATE_LOAD_ERROR, 79 STATE_LOAD_ABORT 80 }; 81 82 LinkManager( SfxObjectShell * pCacheCont ); 83 ~LinkManager(); 84 GetPersist() const85 SfxObjectShell* GetPersist() const { return pPersist; } SetPersist(SfxObjectShell * p)86 void SetPersist( SfxObjectShell * p ) { pPersist = p; } 87 88 void Remove( SvBaseLink *pLink ); 89 void Remove( sal_uInt16 nPos, sal_uInt16 nCnt = 1 ); 90 sal_Bool Insert( SvBaseLink* pLink ); 91 92 // connect the link with a SvLinkSource and insert into the list 93 sal_Bool InsertDDELink( SvBaseLink*, 94 const String& rServer, 95 const String& rTopic, 96 const String& rItem ); 97 98 // in case that all was already adjusted at the link! 99 sal_Bool InsertDDELink( SvBaseLink* ); 100 101 // connect the link with a PseudoObject and insert into the list 102 sal_Bool InsertFileLink( sfx2::SvBaseLink&, 103 sal_uInt16 nFileType, 104 const String& rTxt, 105 const String* pFilterNm = 0, 106 const String* pRange = 0 ); 107 108 // in case that all was already adjusted at the link! 109 sal_Bool InsertFileLink( sfx2::SvBaseLink& ); 110 111 // ask for the strings to be used in the dialog 112 sal_Bool GetDisplayNames( const SvBaseLink *, 113 String* pType, 114 String* pFile = 0, 115 String* pLink = 0, 116 String* pFilter = 0 ) const; 117 118 SvLinkSourceRef CreateObj( SvBaseLink* ); 119 120 /// Ask (once) to allow updating links 121 sal_Bool GetUserAllowsLinkUpdate(Window *pParent); 122 123 // Automatically ask user about update all links, on first insert 124 // If we already asked the user, we forget about it and will ask again. 125 void SetAutoAskUpdateAllLinks(); 126 // Never ask the user: just update all links 127 void SetNeverAskUpdateAllLinks(); 128 129 void UpdateAllLinks( sal_Bool bAskUpdate = sal_True, 130 sal_Bool bCallErrHdl = sal_True, 131 sal_Bool bUpdateGrfLinks = sal_False, 132 Window* pParentWin = 0 ); 133 134 // ask for the list of all links (e.g, for the link dialog) GetLinks() const135 const SvBaseLinks& GetLinks() const { return aLinkTbl; } 136 137 // ----------------- Server-side Management -------------------- 138 139 // ask for the list of all links that get served GetServers() const140 const SvLinkSources& GetServers() const { return aServerTbl; } 141 // insert/delete a served link 142 sal_Bool InsertServer( SvLinkSource* rObj ); 143 void RemoveServer( SvLinkSource* rObj ); RemoveServer(sal_uInt16 nPos,sal_uInt16 nCnt=1)144 void RemoveServer( sal_uInt16 nPos, sal_uInt16 nCnt = 1 ) 145 { aServerTbl.Remove( nPos, nCnt ); } 146 147 // a transfer will be discontinued, therefore cancel all DownloadMedia 148 // (at the moment only interesting for the FileLinks!) 149 150 void CancelTransfers(); 151 152 // to send status information from the FileObject to the BaseLink, there is an own ClipboardId. 153 // The SvData object has then the respective information as string. 154 // Currently this will be used for FileObject in connection with JavaScript 155 // - that needs information about Load/Abort/Error 156 157 static sal_uIntPtr RegisterStatusInfoId(); 158 159 // if the mimetype says graphic/bitmap/gdimetafile then get the 160 // graphic from the Any. Return says no errors 161 static sal_Bool GetGraphicFromAny( const String& rMimeType, 162 const ::com::sun::star::uno::Any & rValue, 163 Graphic& rGrf ); 164 165 // Check whether a link URL must be subject to authorization 166 // 167 // An empty url is considered unsafe 168 sal_Bool urlIsSafe( const ::rtl::OUString &url ); 169 170 // Check whether a link URL must be subject to authorization 171 sal_Bool urlIsSafe( const ::com::sun::star::util::URL &url ); 172 173 // Check whether a link URL is using a ``strange'' scheme 174 sal_Bool urlIsVendor( const ::rtl::OUString &url ); 175 176 private: 177 LinkManager( const LinkManager& ); 178 LinkManager& operator=( const LinkManager& ); 179 }; 180 181 // separator in the LinkName for the DDE/File/Graphic links 182 // (only who needs it, in order to assemble a SvLinkName) 183 const sal_Unicode cTokenSeperator = 0xFFFF; 184 185 // erzeuge einen String fuer den SvLinkName. Fuer 186 // - DDE die ersten 3 Strings, (Server, Topic, Item) 187 // - File-/Grf-LinkNms die letzen 3 Strings (FileName, Bereich, Filter) 188 // create a string for the SvLinkName. For: 189 // - DDE the first 3 strings, (Server, Topic, Item) 190 // - File/Graphic LinkNames the last 3 strings (FileName, Area, Filter) 191 SFX2_DLLPUBLIC void MakeLnkName( String& rName, 192 const String* pType, // can also be 0! 193 const String& rFile, 194 const String& rLink, 195 const String* pFilter = 0 ); 196 197 } 198 199 #endif 200