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 24 #ifndef SD_FRAMEWORK_RESOURCE_ID_HXX 25 #define SD_FRAMEWORK_RESOURCE_ID_HXX 26 27 #include <com/sun/star/drawing/framework/XResourceId.hpp> 28 #include <com/sun/star/lang/XInitialization.hpp> 29 #include <com/sun/star/util/XURLTransformer.hpp> 30 #include <cppuhelper/compbase2.hxx> 31 #include <boost/scoped_ptr.hpp> 32 33 namespace css = ::com::sun::star; 34 35 36 namespace { 37 38 typedef ::cppu::WeakImplHelper2 < 39 css::drawing::framework::XResourceId, 40 css::lang::XInitialization 41 > ResourceIdInterfaceBase; 42 43 } // end of anonymous namespace. 44 45 46 47 48 namespace sd { namespace framework { 49 50 /** Implementation of the css::drawing::framework::ResourceId 51 service and the css::drawing::framework::XResourceId 52 interface. 53 */ 54 class ResourceId 55 : public ResourceIdInterfaceBase 56 { 57 public: 58 /** Create a new, empty resource id. 59 */ 60 ResourceId (void); 61 62 /** Create a new resource id that is described by the given URLs. 63 @param rsResourceURLs 64 The first URL specifies the type of resource. The other URLs 65 describe its anchor. 66 The set of URLs may be empty. The result is then the same as 67 returned by ResourceId() default constructor. 68 */ 69 ResourceId (const ::std::vector<rtl::OUString>& rsResourceURLs); 70 71 /** Create a new resource id that has an empty anchor. 72 @param rsResourceURL 73 When this resource URL is empty then the resulting ResourceId 74 object is identical to when the ResourceId() default constructor 75 had been called. 76 */ 77 ResourceId ( 78 const ::rtl::OUString& rsResourceURL); 79 80 /** Create a new resource id for the given resource type and an anchor 81 that is specified by a single URL. This constructor can be used for 82 example for views that are bound to panes. 83 @param rsResourceURL 84 The URL of the actual resource. 85 @param rsAnchorURL 86 The single URL of the anchor. 87 */ 88 ResourceId ( 89 const ::rtl::OUString& rsResourceURL, 90 const ::rtl::OUString& rsAnchorURL); 91 92 /** Create a new resource id for the specified resource type and the 93 given list of anchor URLs. 94 @param rsResourceURL 95 The URL of the actual resource. 96 @param rsAnchorURLs 97 The possibly empty list of anchor URLs. 98 */ 99 ResourceId ( 100 const ::rtl::OUString& rsResourceURL, 101 const ::std::vector<rtl::OUString>& rAnchorURLs); 102 103 /** Create a new resource id with an anchor that consists of a sequence 104 of URLs that is extended by a further URL. 105 @param rsResourceURL 106 The URL of the actual resource. 107 @param rsFirstAnchorURL 108 This URL extends the anchor given by rAnchorURLs. 109 @param rAnchorURLs 110 An anchor as it is returned by XResourceId::getAnchorURLs(). 111 */ 112 ResourceId ( 113 const ::rtl::OUString& rsResourceURL, 114 const ::rtl::OUString& rsFirstAnchorURL, 115 const css::uno::Sequence<rtl::OUString>& rAnchorURLs); 116 117 virtual ~ResourceId (void); 118 119 /** Return the list of URLs of both the resource URL and the anchor 120 URLs. 121 */ 122 const ::std::vector<rtl::OUString>& GetResourceURLs (void) const; 123 124 //===== XResourceId ======================================================= 125 126 virtual ::rtl::OUString SAL_CALL 127 getResourceURL (void); 128 129 virtual css::util::URL SAL_CALL 130 getFullResourceURL (void); 131 132 virtual sal_Bool SAL_CALL 133 hasAnchor (void); 134 135 virtual css::uno::Reference< 136 css::drawing::framework::XResourceId> SAL_CALL 137 getAnchor (void); 138 139 virtual css::uno::Sequence<rtl::OUString> SAL_CALL 140 getAnchorURLs (void); 141 142 virtual ::rtl::OUString SAL_CALL 143 getResourceTypePrefix (void); 144 145 virtual sal_Int16 SAL_CALL 146 compareTo (const css::uno::Reference< 147 css::drawing::framework::XResourceId>& rxResourceId); 148 149 virtual sal_Bool SAL_CALL 150 isBoundTo ( 151 const css::uno::Reference< 152 css::drawing::framework::XResourceId>& rxResourceId, 153 css::drawing::framework::AnchorBindingMode eMode); 154 155 virtual sal_Bool SAL_CALL 156 isBoundToURL ( 157 const ::rtl::OUString& rsAnchorURL, 158 css::drawing::framework::AnchorBindingMode eMode); 159 160 virtual css::uno::Reference< 161 css::drawing::framework::XResourceId> SAL_CALL 162 clone (void); 163 164 //===== XInitialization =================================================== 165 166 void SAL_CALL initialize ( 167 const css::uno::Sequence<css::uno::Any>& aArguments); 168 169 private: 170 /** The set of URLs that consist of the resource URL at index 0 and the 171 anchor URLs and indices 1 and above. 172 */ 173 ::std::vector<rtl::OUString> maResourceURLs; 174 175 ::boost::scoped_ptr<css::util::URL> mpURL; 176 177 static css::uno::WeakReference<css::util::XURLTransformer> mxURLTransformerWeak; 178 179 /** Compare the called ResourceId object to the given ResourceId object. 180 This uses the implementation of both objects to speed up the 181 comparison. 182 */ 183 sal_Int16 CompareToLocalImplementation (const ResourceId& rId) const; 184 185 /** Compare the called ResourceId object to the given XResourceId object 186 reference. The comparison is done via the UNO interface. Namely, 187 it uses the getResourceURL() and the getAnchorURLs() methods to get 188 access to the URLs of the given objec. 189 */ 190 sal_Int16 CompareToExternalImplementation (const css::uno::Reference< 191 css::drawing::framework::XResourceId>& rxId) const; 192 193 /** Return whether the called ResourceId object is bound to the anchor 194 consisting of the URLs given by psFirstAnchorURL and paAnchorURLs. 195 @param psFirstAnchorURL 196 Optional first URL of the anchor. This can be missing or present 197 independently of paAnchorURLs. 198 @param paAnchorURLs 199 Optional set of additional anchor URLs. This can be missing or 200 present independently of psFirstAnchorURL. 201 @param eMode 202 This specifies whether the called resource has to be directly 203 bound to the given anchor in order to return <TRUE/> or whether 204 it can be bound indirectly, too. 205 */ 206 bool IsBoundToAnchor ( 207 const rtl::OUString* psFirstAnchorURL, 208 const css::uno::Sequence<rtl::OUString>* paAnchorURLs, 209 css::drawing::framework::AnchorBindingMode eMode) const; 210 211 /** Return whether the called ResourceId object is bound to the anchor 212 consisting of the URLs in rResourceURLs. 213 @param rResourceURLs 214 A possibly empty list of anchor URLs. 215 @param eMode 216 This specifies whether the called resource has to be directly 217 bound to the given anchor in order to return <TRUE/> or whether 218 it can be bound indirectly, too. 219 */ 220 bool IsBoundToAnchor ( 221 const ::std::vector<rtl::OUString>& rResourceURLs, 222 css::drawing::framework::AnchorBindingMode eMode) const; 223 224 void ParseResourceURL (void); 225 }; 226 227 } } // end of namespace sd::framework 228 229 #endif 230