1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_FRAMEWORK_CONFIGURATION_CLASSIFIER_HXX 29 #define SD_FRAMEWORK_CONFIGURATION_CLASSIFIER_HXX 30 31 #include <com/sun/star/drawing/framework/XConfiguration.hpp> 32 33 #include <vector> 34 35 namespace sd { namespace framework { 36 37 /** A ConfigurationClassifier object compares two configurations of 38 resources and gives access to the differences. It is used mainly when 39 changes to the current configuration have been requested and the various 40 resource controllers have to be supplied with the set of resources that 41 are to be activated or deactivated. 42 */ 43 class ConfigurationClassifier 44 { 45 public: 46 /** Create a new ConfigurationClassifier object that will compare the 47 two given configurations. 48 */ 49 ConfigurationClassifier ( 50 const ::com::sun::star::uno::Reference< 51 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration1, 52 const ::com::sun::star::uno::Reference< 53 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration2); 54 55 /** Calculate three lists of resource ids. These contain the resources 56 that belong to one configuration but not the other, or that belong 57 to both configurations. 58 @return 59 When the two configurations differ then return <TRUE/>. When 60 they are equivalent then return <FALSE/>. 61 */ 62 bool Partition (void); 63 64 typedef ::std::vector<com::sun::star::uno::Reference< 65 ::com::sun::star::drawing::framework::XResourceId> > ResourceIdVector; 66 67 /** Return the resources that belong to the configuration given as 68 rxConfiguration1 to the constructor but that do not belong to 69 rxConfiguration2. 70 @return 71 A reference to the, possibly empty, list of resources is 72 returned. This reference remains valid as long as the called 73 ConfigurationClassifier object stays alive. 74 */ 75 const ResourceIdVector& GetC1minusC2 (void) const; 76 77 /** Return the resources that belong to the configuration given as 78 rxConfiguration2 to the constructor but that do not belong to 79 rxConfiguration1. 80 @return 81 A reference to the, possibly empty, list of resources is 82 returned. This reference remains valid as long as the called 83 ConfigurationClassifier object stays alive. 84 */ 85 const ResourceIdVector& GetC2minusC1 (void) const; 86 87 /** Return the resources that belong to both the configurations that 88 where given to the constructor. 89 @return 90 A reference to the, possibly empty, list of resources is 91 returned. This reference remains valid as long as the called 92 ConfigurationClassifier object stays alive. 93 */ 94 const ResourceIdVector& GetC1andC2 (void) const; 95 96 void TraceResourceIdVector ( 97 const sal_Char* pMessage, 98 const ResourceIdVector& rResources) const; 99 100 private: 101 ::com::sun::star::uno::Reference< 102 ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration1; 103 ::com::sun::star::uno::Reference< 104 ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration2; 105 106 /** After the call to Classify() this vector holds all elements from 107 mxConfiguration1 that are not in mxConfiguration2. 108 */ 109 ResourceIdVector maC1minusC2; 110 111 /** After the call to Classify() this vector holds all elements from 112 mxConfiguration2 that are not in mxConfiguration1. 113 */ 114 ResourceIdVector maC2minusC1; 115 116 /** After the call to Classify() this vector holds all elements that are 117 member both of mxConfiguration1 and mxConfiguration2. 118 */ 119 ResourceIdVector maC1andC2; 120 121 /** Put all the elements in the two gven sequences of resource ids and 122 copy them into one of the resource id result vectors maC1minusC2, 123 maC2minusC1, and maC1andC2. This is done by using only the resource 124 URLs for classification. Therefor this method calls itself 125 recursively. 126 @param rS1 127 One sequence of XResourceId objects. 128 @param rS2 129 Another sequence of XResourceId objects. 130 */ 131 void PartitionResources ( 132 const ::com::sun::star::uno::Sequence< 133 ::com::sun::star::uno::Reference< 134 ::com::sun::star::drawing::framework::XResourceId> >& rS1, 135 const ::com::sun::star::uno::Sequence< 136 ::com::sun::star::uno::Reference< 137 ::com::sun::star::drawing::framework::XResourceId> >& rS2); 138 139 /** Compare the given sequences of resource ids and put their elements 140 in one of three vectors depending on whether an element belongs to 141 both sequences or to one but not the other. Note that only the 142 resource URLs of the XResourceId objects are used for the 143 classification. 144 @param rS1 145 One sequence of XResourceId objects. 146 @param rS2 147 Another sequence of XResourceId objects. 148 */ 149 void ClassifyResources ( 150 const ::com::sun::star::uno::Sequence< 151 ::com::sun::star::uno::Reference< 152 ::com::sun::star::drawing::framework::XResourceId> >& rS1, 153 const ::com::sun::star::uno::Sequence< 154 ::com::sun::star::uno::Reference< 155 ::com::sun::star::drawing::framework::XResourceId> >& rS2, 156 ResourceIdVector& rS1minusS2, 157 ResourceIdVector& rS2minusS1, 158 ResourceIdVector& rS1andS2); 159 160 161 /** Copy the resources given in rSource to the list of resources 162 specified by rTarget. Resources bound to the ones in rSource, 163 either directly or indirectly, are copied as well. 164 @param rSource 165 All resources and the ones bound to them, either directly or 166 indirectly, are copied. 167 @param rxConfiguration 168 This configuration is used to determine the resources bound to 169 the ones in rSource. 170 @param rTarget 171 This list is filled with resources from rSource and the ones 172 bound to them. 173 */ 174 void CopyResources ( 175 const ResourceIdVector& rSource, 176 const ::com::sun::star::uno::Reference< 177 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration, 178 ResourceIdVector& rTarget); 179 }; 180 181 } } // end of namespace sd::framework 182 183 #endif 184