1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <swtypes.hxx>
29cdf0e10cSrcweir #include <labelcfg.hxx>
30cdf0e10cSrcweir #include <labimp.hxx>
31cdf0e10cSrcweir #include <unotools/configpathes.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <unomid.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir using namespace utl;
36cdf0e10cSrcweir using namespace rtl;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::beans;
39cdf0e10cSrcweir
40cdf0e10cSrcweir /* -----------------------------15.01.01 11:17--------------------------------
41cdf0e10cSrcweir
42cdf0e10cSrcweir ---------------------------------------------------------------------------*/
SwLabelConfig()43cdf0e10cSrcweir SwLabelConfig::SwLabelConfig() :
44cdf0e10cSrcweir ConfigItem(C2U("Office.Labels/Manufacturer"))
45cdf0e10cSrcweir {
46cdf0e10cSrcweir aNodeNames = GetNodeNames(OUString());
47cdf0e10cSrcweir }
48cdf0e10cSrcweir /* -----------------------------06.09.00 16:50--------------------------------
49cdf0e10cSrcweir
50cdf0e10cSrcweir ---------------------------------------------------------------------------*/
~SwLabelConfig()51cdf0e10cSrcweir SwLabelConfig::~SwLabelConfig()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir /* -----------------------------06.09.00 16:43--------------------------------
55cdf0e10cSrcweir
56cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Commit()57cdf0e10cSrcweir void SwLabelConfig::Commit()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir // the config item is not writable yet
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
Notify(const::com::sun::star::uno::Sequence<rtl::OUString> &)62cdf0e10cSrcweir void SwLabelConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
63cdf0e10cSrcweir
64cdf0e10cSrcweir /* -----------------------------15.01.01 11:42--------------------------------
65cdf0e10cSrcweir
66cdf0e10cSrcweir ---------------------------------------------------------------------------*/
lcl_CreatePropertyNames(const OUString & rPrefix)67cdf0e10cSrcweir Sequence<OUString> lcl_CreatePropertyNames(const OUString& rPrefix)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir Sequence<OUString> aProperties(2);
70cdf0e10cSrcweir OUString* pProperties = aProperties.getArray();
71cdf0e10cSrcweir for(sal_Int32 nProp = 0; nProp < 2; nProp++)
72cdf0e10cSrcweir pProperties[nProp] = rPrefix;
73cdf0e10cSrcweir
74cdf0e10cSrcweir pProperties[ 0] += C2U("Name");
75cdf0e10cSrcweir pProperties[ 1] += C2U("Measure");
76cdf0e10cSrcweir return aProperties;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir //-----------------------------------------------------------------------------
lcl_CreateSwLabRec(Sequence<Any> & rValues,const OUString & rManufacturer)79cdf0e10cSrcweir SwLabRec* lcl_CreateSwLabRec(Sequence<Any>& rValues, const OUString& rManufacturer)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir SwLabRec* pNewRec = new SwLabRec;
82cdf0e10cSrcweir const Any* pValues = rValues.getConstArray();
83cdf0e10cSrcweir OUString sTmp;
84cdf0e10cSrcweir pNewRec->aMake = rManufacturer;
85cdf0e10cSrcweir for(sal_Int32 nProp = 0; nProp < rValues.getLength(); nProp++)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir if(pValues[nProp].hasValue())
88cdf0e10cSrcweir {
89cdf0e10cSrcweir switch(nProp)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir case 0: pValues[nProp] >>= sTmp; pNewRec->aType = sTmp; break;
92cdf0e10cSrcweir case 1:
93cdf0e10cSrcweir {
94cdf0e10cSrcweir //all values are contained as colon-separated 1/100 mm values except for the
95cdf0e10cSrcweir //continuous flag ('C'/'S')
96cdf0e10cSrcweir pValues[nProp] >>= sTmp;
97cdf0e10cSrcweir String sMeasure(sTmp);
98cdf0e10cSrcweir sal_uInt16 nTokenCount = sMeasure.GetTokenCount(';');
99cdf0e10cSrcweir for(sal_uInt16 i = 0; i < nTokenCount; i++)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir String sToken(sMeasure.GetToken(i, ';' ));
102cdf0e10cSrcweir int nVal = sToken.ToInt32();
103cdf0e10cSrcweir switch(i)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir case 0 : pNewRec->bCont = sToken.GetChar(0) == 'C'; break;
106cdf0e10cSrcweir case 1 : pNewRec->lHDist = MM100_TO_TWIP(nVal);break;
107cdf0e10cSrcweir case 2 : pNewRec->lVDist = MM100_TO_TWIP(nVal);break;
108cdf0e10cSrcweir case 3 : pNewRec->lWidth = MM100_TO_TWIP(nVal);break;
109cdf0e10cSrcweir case 4 : pNewRec->lHeight = MM100_TO_TWIP(nVal); break;
110cdf0e10cSrcweir case 5 : pNewRec->lLeft = MM100_TO_TWIP(nVal);break;
111cdf0e10cSrcweir case 6 : pNewRec->lUpper = MM100_TO_TWIP(nVal);break;
112cdf0e10cSrcweir case 7 : pNewRec->nCols = nVal; break;
113cdf0e10cSrcweir case 8 : pNewRec->nRows = nVal; break;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir break;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir }
121cdf0e10cSrcweir return pNewRec;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir //-----------------------------------------------------------------------------
lcl_CreateProperties(Sequence<OUString> & rPropNames,const SwLabRec & rRec)124cdf0e10cSrcweir Sequence<PropertyValue> lcl_CreateProperties(
125cdf0e10cSrcweir Sequence<OUString>& rPropNames, const SwLabRec& rRec)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir const OUString* pNames = rPropNames.getConstArray();
128cdf0e10cSrcweir Sequence<PropertyValue> aRet(rPropNames.getLength());
129cdf0e10cSrcweir PropertyValue* pValues = aRet.getArray();
130cdf0e10cSrcweir OUString sColon(C2U(";"));
131cdf0e10cSrcweir
132cdf0e10cSrcweir for(sal_Int32 nProp = 0; nProp < rPropNames.getLength(); nProp++)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir pValues[nProp].Name = pNames[nProp];
135cdf0e10cSrcweir switch(nProp)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir case 0: pValues[nProp].Value <<= OUString(rRec.aType); break;
138cdf0e10cSrcweir case 1:
139cdf0e10cSrcweir {
140cdf0e10cSrcweir OUString sTmp;
141cdf0e10cSrcweir sTmp += C2U( rRec.bCont ? "C" : "S"); sTmp += sColon;
142cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHDist) ); sTmp += sColon;
143cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lVDist)); sTmp += sColon;
144cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lWidth) ); sTmp += sColon;
145cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHeight) ); sTmp += sColon;
146cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lLeft) ); sTmp += sColon;
147cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lUpper) ); sTmp += sColon;
148cdf0e10cSrcweir sTmp += OUString::valueOf(rRec.nCols );sTmp += sColon;
149cdf0e10cSrcweir sTmp += OUString::valueOf(rRec.nRows );
150cdf0e10cSrcweir pValues[nProp].Value <<= sTmp;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir break;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir return aRet;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir //-----------------------------------------------------------------------------
FillLabels(const OUString & rManufacturer,SwLabRecs & rLabArr)158cdf0e10cSrcweir void SwLabelConfig::FillLabels(const OUString& rManufacturer, SwLabRecs& rLabArr)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
161cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
162cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
163cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir OUString sPrefix(sManufacturer);
166cdf0e10cSrcweir sPrefix += C2U("/");
167cdf0e10cSrcweir sPrefix += pLabels[nLabel];
168cdf0e10cSrcweir sPrefix += C2U("/");
169cdf0e10cSrcweir Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
170cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aPropNames);
171cdf0e10cSrcweir SwLabRec* pNewRec = lcl_CreateSwLabRec(aValues, rManufacturer);
172cdf0e10cSrcweir rLabArr.C40_INSERT( SwLabRec, pNewRec, rLabArr.Count() );
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir /* -----------------------------23.01.01 11:36--------------------------------
176cdf0e10cSrcweir
177cdf0e10cSrcweir ---------------------------------------------------------------------------*/
HasLabel(const rtl::OUString & rManufacturer,const rtl::OUString & rType)178cdf0e10cSrcweir sal_Bool SwLabelConfig::HasLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir const OUString* pNode = aNodeNames.getConstArray();
181cdf0e10cSrcweir sal_Bool bFound = sal_False;
182cdf0e10cSrcweir for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir if(pNode[nNode] == rManufacturer)
185cdf0e10cSrcweir bFound = sal_True;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir if(bFound)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
190cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
191cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
192cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir OUString sPrefix(sManufacturer);
195cdf0e10cSrcweir sPrefix += C2U("/");
196cdf0e10cSrcweir sPrefix += pLabels[nLabel];
197cdf0e10cSrcweir sPrefix += C2U("/");
198cdf0e10cSrcweir Sequence<OUString> aProperties(1);
199cdf0e10cSrcweir aProperties.getArray()[0] = sPrefix;
200cdf0e10cSrcweir aProperties.getArray()[0] += C2U("Name");
201cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aProperties);
202cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
203cdf0e10cSrcweir if(pValues[0].hasValue())
204cdf0e10cSrcweir {
205cdf0e10cSrcweir OUString sTmp;
206cdf0e10cSrcweir pValues[0] >>= sTmp;
207cdf0e10cSrcweir if(rType == sTmp)
208cdf0e10cSrcweir return sal_True;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir return sal_False;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir /* -----------------------------23.01.01 11:36--------------------------------
215cdf0e10cSrcweir
216cdf0e10cSrcweir ---------------------------------------------------------------------------*/
lcl_Exists(const OUString & rNode,const Sequence<OUString> & rLabels)217cdf0e10cSrcweir sal_Bool lcl_Exists(const OUString& rNode, const Sequence<OUString>& rLabels)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir const OUString* pLabels = rLabels.getConstArray();
220cdf0e10cSrcweir for(sal_Int32 i = 0; i < rLabels.getLength(); i++)
221cdf0e10cSrcweir if(pLabels[i] == rNode)
222cdf0e10cSrcweir return sal_True;
223cdf0e10cSrcweir return sal_False;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir //-----------------------------------------------------------------------------
SaveLabel(const rtl::OUString & rManufacturer,const rtl::OUString & rType,const SwLabRec & rRec)226cdf0e10cSrcweir void SwLabelConfig::SaveLabel( const rtl::OUString& rManufacturer,
227cdf0e10cSrcweir const rtl::OUString& rType, const SwLabRec& rRec)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir const OUString* pNode = aNodeNames.getConstArray();
230cdf0e10cSrcweir sal_Bool bFound = sal_False;
231cdf0e10cSrcweir for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir if(pNode[nNode] == rManufacturer)
234cdf0e10cSrcweir bFound = sal_True;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir if(!bFound)
237cdf0e10cSrcweir {
238cdf0e10cSrcweir if(!AddNode(OUString(), rManufacturer))
239cdf0e10cSrcweir {
240cdf0e10cSrcweir DBG_ERROR("New configuration node could not be created");
241cdf0e10cSrcweir return ;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir else
244cdf0e10cSrcweir {
245cdf0e10cSrcweir aNodeNames = GetNodeNames(OUString());
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
250cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
251cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
252cdf0e10cSrcweir OUString sFoundNode;
253cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir OUString sPrefix(sManufacturer);
256cdf0e10cSrcweir sPrefix += C2U("/");
257cdf0e10cSrcweir sPrefix += pLabels[nLabel];
258cdf0e10cSrcweir sPrefix += C2U("/");
259cdf0e10cSrcweir Sequence<OUString> aProperties(1);
260cdf0e10cSrcweir aProperties.getArray()[0] = sPrefix;
261cdf0e10cSrcweir aProperties.getArray()[0] += C2U("Name");
262cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aProperties);
263cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
264cdf0e10cSrcweir if(pValues[0].hasValue())
265cdf0e10cSrcweir {
266cdf0e10cSrcweir OUString sTmp;
267cdf0e10cSrcweir pValues[0] >>= sTmp;
268cdf0e10cSrcweir if(rType == sTmp)
269cdf0e10cSrcweir {
270cdf0e10cSrcweir sFoundNode = pLabels[nLabel];
271cdf0e10cSrcweir break;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir // if not found - generate a unique node name
276cdf0e10cSrcweir if(!sFoundNode.getLength())
277cdf0e10cSrcweir {
278cdf0e10cSrcweir sal_Int32 nIndex = aLabels.getLength();
279cdf0e10cSrcweir OUString sPrefix(C2U("Label"));
280cdf0e10cSrcweir sFoundNode = sPrefix;
281cdf0e10cSrcweir sFoundNode += OUString::valueOf(nIndex);
282cdf0e10cSrcweir while(lcl_Exists(sFoundNode, aLabels))
283cdf0e10cSrcweir {
284cdf0e10cSrcweir sFoundNode = sPrefix;
285cdf0e10cSrcweir sFoundNode += OUString::valueOf(nIndex++);
286cdf0e10cSrcweir }
287cdf0e10cSrcweir }
288cdf0e10cSrcweir OUString sPrefix(wrapConfigurationElementName(rManufacturer));
289cdf0e10cSrcweir sPrefix += C2U("/");
290cdf0e10cSrcweir sPrefix += sFoundNode;
291cdf0e10cSrcweir sPrefix += C2U("/");
292cdf0e10cSrcweir Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
293cdf0e10cSrcweir Sequence<PropertyValue> aPropValues = lcl_CreateProperties(aPropNames, rRec);
294cdf0e10cSrcweir SetSetProperties(wrapConfigurationElementName(rManufacturer), aPropValues);
295cdf0e10cSrcweir
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir
299