Line data Source code
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 : #ifndef INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCLASSIFIER_HXX
21 : #define INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONCLASSIFIER_HXX
22 :
23 : #include <com/sun/star/drawing/framework/XConfiguration.hpp>
24 :
25 : #include <vector>
26 :
27 : namespace sd { namespace framework {
28 :
29 : /** A ConfigurationClassifier object compares two configurations of
30 : resources and gives access to the differences. It is used mainly when
31 : changes to the current configuration have been requested and the various
32 : resource controllers have to be supplied with the set of resources that
33 : are to be activated or deactivated.
34 : */
35 920 : class ConfigurationClassifier
36 : {
37 : public:
38 : /** Create a new ConfigurationClassifier object that will compare the
39 : two given configurations.
40 : */
41 : ConfigurationClassifier (
42 : const ::com::sun::star::uno::Reference<
43 : ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration1,
44 : const ::com::sun::star::uno::Reference<
45 : ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration2);
46 :
47 : /** Calculate three lists of resource ids. These contain the resources
48 : that belong to one configuration but not the other, or that belong
49 : to both configurations.
50 : @return
51 : When the two configurations differ then return <TRUE/>. When
52 : they are equivalent then return <FALSE/>.
53 : */
54 : bool Partition (void);
55 :
56 : typedef ::std::vector<com::sun::star::uno::Reference<
57 : ::com::sun::star::drawing::framework::XResourceId> > ResourceIdVector;
58 :
59 : /** Return the resources that belong to the configuration given as
60 : rxConfiguration1 to the constructor but that do not belong to
61 : rxConfiguration2.
62 : @return
63 : A reference to the, possibly empty, list of resources is
64 : returned. This reference remains valid as long as the called
65 : ConfigurationClassifier object stays alive.
66 : */
67 796 : const ResourceIdVector& GetC1minusC2 (void) const { return maC1minusC2;}
68 :
69 : /** Return the resources that belong to the configuration given as
70 : rxConfiguration2 to the constructor but that do not belong to
71 : rxConfiguration1.
72 : @return
73 : A reference to the, possibly empty, list of resources is
74 : returned. This reference remains valid as long as the called
75 : ConfigurationClassifier object stays alive.
76 : */
77 796 : const ResourceIdVector& GetC2minusC1 (void) const { return maC2minusC1;}
78 :
79 : /** Return the resources that belong to both the configurations that
80 : where given to the constructor.
81 : @return
82 : A reference to the, possibly empty, list of resources is
83 : returned. This reference remains valid as long as the called
84 : ConfigurationClassifier object stays alive.
85 : */
86 : const ResourceIdVector& GetC1andC2 (void) const { return maC1andC2;}
87 :
88 : void TraceResourceIdVector (
89 : const sal_Char* pMessage,
90 : const ResourceIdVector& rResources) const;
91 :
92 : private:
93 : ::com::sun::star::uno::Reference<
94 : ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration1;
95 : ::com::sun::star::uno::Reference<
96 : ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration2;
97 :
98 : /** After the call to Classify() this vector holds all elements from
99 : mxConfiguration1 that are not in mxConfiguration2.
100 : */
101 : ResourceIdVector maC1minusC2;
102 :
103 : /** After the call to Classify() this vector holds all elements from
104 : mxConfiguration2 that are not in mxConfiguration1.
105 : */
106 : ResourceIdVector maC2minusC1;
107 :
108 : /** After the call to Classify() this vector holds all elements that are
109 : member both of mxConfiguration1 and mxConfiguration2.
110 : */
111 : ResourceIdVector maC1andC2;
112 :
113 : /** Put all the elements in the two given sequences of resource ids and
114 : copy them into one of the resource id result vectors maC1minusC2,
115 : maC2minusC1, and maC1andC2. This is done by using only the resource
116 : URLs for classification. Therefore this method calls itself
117 : recursively.
118 : @param rS1
119 : One sequence of XResourceId objects.
120 : @param rS2
121 : Another sequence of XResourceId objects.
122 : */
123 : void PartitionResources (
124 : const ::com::sun::star::uno::Sequence<
125 : ::com::sun::star::uno::Reference<
126 : ::com::sun::star::drawing::framework::XResourceId> >& rS1,
127 : const ::com::sun::star::uno::Sequence<
128 : ::com::sun::star::uno::Reference<
129 : ::com::sun::star::drawing::framework::XResourceId> >& rS2);
130 :
131 : /** Compare the given sequences of resource ids and put their elements
132 : in one of three vectors depending on whether an element belongs to
133 : both sequences or to one but not the other. Note that only the
134 : resource URLs of the XResourceId objects are used for the
135 : classification.
136 : @param rS1
137 : One sequence of XResourceId objects.
138 : @param rS2
139 : Another sequence of XResourceId objects.
140 : */
141 : void ClassifyResources (
142 : const ::com::sun::star::uno::Sequence<
143 : ::com::sun::star::uno::Reference<
144 : ::com::sun::star::drawing::framework::XResourceId> >& rS1,
145 : const ::com::sun::star::uno::Sequence<
146 : ::com::sun::star::uno::Reference<
147 : ::com::sun::star::drawing::framework::XResourceId> >& rS2,
148 : ResourceIdVector& rS1minusS2,
149 : ResourceIdVector& rS2minusS1,
150 : ResourceIdVector& rS1andS2);
151 :
152 : /** Copy the resources given in rSource to the list of resources
153 : specified by rTarget. Resources bound to the ones in rSource,
154 : either directly or indirectly, are copied as well.
155 : @param rSource
156 : All resources and the ones bound to them, either directly or
157 : indirectly, are copied.
158 : @param rxConfiguration
159 : This configuration is used to determine the resources bound to
160 : the ones in rSource.
161 : @param rTarget
162 : This list is filled with resources from rSource and the ones
163 : bound to them.
164 : */
165 : void CopyResources (
166 : const ResourceIdVector& rSource,
167 : const ::com::sun::star::uno::Reference<
168 : ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration,
169 : ResourceIdVector& rTarget);
170 : };
171 :
172 : } } // end of namespace sd::framework
173 :
174 : #endif
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|