1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10efeef26fSAndrew Rist *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19efeef26fSAndrew Rist *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew 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;
114*737f4475STsutomu Uchino case 9 : pNewRec->lPaperWidth = MM100_TO_TWIP(nVal);break;
115*737f4475STsutomu Uchino case 10: pNewRec->lPaperHeight = MM100_TO_TWIP(nVal);break;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir break;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir return pNewRec;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir //-----------------------------------------------------------------------------
lcl_CreateProperties(Sequence<OUString> & rPropNames,const SwLabRec & rRec)126cdf0e10cSrcweir Sequence<PropertyValue> lcl_CreateProperties(
127cdf0e10cSrcweir Sequence<OUString>& rPropNames, const SwLabRec& rRec)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir const OUString* pNames = rPropNames.getConstArray();
130cdf0e10cSrcweir Sequence<PropertyValue> aRet(rPropNames.getLength());
131cdf0e10cSrcweir PropertyValue* pValues = aRet.getArray();
132cdf0e10cSrcweir OUString sColon(C2U(";"));
133cdf0e10cSrcweir
134cdf0e10cSrcweir for(sal_Int32 nProp = 0; nProp < rPropNames.getLength(); nProp++)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir pValues[nProp].Name = pNames[nProp];
137cdf0e10cSrcweir switch(nProp)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir case 0: pValues[nProp].Value <<= OUString(rRec.aType); break;
140cdf0e10cSrcweir case 1:
141cdf0e10cSrcweir {
142cdf0e10cSrcweir OUString sTmp;
143cdf0e10cSrcweir sTmp += C2U( rRec.bCont ? "C" : "S"); sTmp += sColon;
144cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHDist) ); sTmp += sColon;
145cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lVDist)); sTmp += sColon;
146cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lWidth) ); sTmp += sColon;
147cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHeight) ); sTmp += sColon;
148cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lLeft) ); sTmp += sColon;
149cdf0e10cSrcweir sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lUpper) ); sTmp += sColon;
150cdf0e10cSrcweir sTmp += OUString::valueOf(rRec.nCols );sTmp += sColon;
151*737f4475STsutomu Uchino sTmp += OUString::valueOf(rRec.nRows );sTmp += sColon;
152*737f4475STsutomu Uchino sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lPaperWidth));sTmp += sColon;
153*737f4475STsutomu Uchino sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lPaperHeight));
154cdf0e10cSrcweir pValues[nProp].Value <<= sTmp;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir return aRet;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir //-----------------------------------------------------------------------------
FillLabels(const OUString & rManufacturer,SwLabRecs & rLabArr)162cdf0e10cSrcweir void SwLabelConfig::FillLabels(const OUString& rManufacturer, SwLabRecs& rLabArr)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
165cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
166cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
167cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir OUString sPrefix(sManufacturer);
170cdf0e10cSrcweir sPrefix += C2U("/");
171cdf0e10cSrcweir sPrefix += pLabels[nLabel];
172cdf0e10cSrcweir sPrefix += C2U("/");
173cdf0e10cSrcweir Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
174cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aPropNames);
175cdf0e10cSrcweir SwLabRec* pNewRec = lcl_CreateSwLabRec(aValues, rManufacturer);
176cdf0e10cSrcweir rLabArr.C40_INSERT( SwLabRec, pNewRec, rLabArr.Count() );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir /* -----------------------------23.01.01 11:36--------------------------------
180cdf0e10cSrcweir
181cdf0e10cSrcweir ---------------------------------------------------------------------------*/
HasLabel(const rtl::OUString & rManufacturer,const rtl::OUString & rType)182cdf0e10cSrcweir sal_Bool SwLabelConfig::HasLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir const OUString* pNode = aNodeNames.getConstArray();
185cdf0e10cSrcweir sal_Bool bFound = sal_False;
186cdf0e10cSrcweir for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir if(pNode[nNode] == rManufacturer)
189cdf0e10cSrcweir bFound = sal_True;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir if(bFound)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
194cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
195cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
196cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir OUString sPrefix(sManufacturer);
199cdf0e10cSrcweir sPrefix += C2U("/");
200cdf0e10cSrcweir sPrefix += pLabels[nLabel];
201cdf0e10cSrcweir sPrefix += C2U("/");
202cdf0e10cSrcweir Sequence<OUString> aProperties(1);
203cdf0e10cSrcweir aProperties.getArray()[0] = sPrefix;
204cdf0e10cSrcweir aProperties.getArray()[0] += C2U("Name");
205cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aProperties);
206cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
207cdf0e10cSrcweir if(pValues[0].hasValue())
208cdf0e10cSrcweir {
209cdf0e10cSrcweir OUString sTmp;
210cdf0e10cSrcweir pValues[0] >>= sTmp;
211cdf0e10cSrcweir if(rType == sTmp)
212cdf0e10cSrcweir return sal_True;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir }
216cdf0e10cSrcweir return sal_False;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir /* -----------------------------23.01.01 11:36--------------------------------
219cdf0e10cSrcweir
220cdf0e10cSrcweir ---------------------------------------------------------------------------*/
lcl_Exists(const OUString & rNode,const Sequence<OUString> & rLabels)221cdf0e10cSrcweir sal_Bool lcl_Exists(const OUString& rNode, const Sequence<OUString>& rLabels)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir const OUString* pLabels = rLabels.getConstArray();
224cdf0e10cSrcweir for(sal_Int32 i = 0; i < rLabels.getLength(); i++)
225cdf0e10cSrcweir if(pLabels[i] == rNode)
226cdf0e10cSrcweir return sal_True;
227cdf0e10cSrcweir return sal_False;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir //-----------------------------------------------------------------------------
SaveLabel(const rtl::OUString & rManufacturer,const rtl::OUString & rType,const SwLabRec & rRec)230cdf0e10cSrcweir void SwLabelConfig::SaveLabel( const rtl::OUString& rManufacturer,
231cdf0e10cSrcweir const rtl::OUString& rType, const SwLabRec& rRec)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir const OUString* pNode = aNodeNames.getConstArray();
234cdf0e10cSrcweir sal_Bool bFound = sal_False;
235cdf0e10cSrcweir for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir if(pNode[nNode] == rManufacturer)
238cdf0e10cSrcweir bFound = sal_True;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir if(!bFound)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if(!AddNode(OUString(), rManufacturer))
243cdf0e10cSrcweir {
244cdf0e10cSrcweir DBG_ERROR("New configuration node could not be created");
245cdf0e10cSrcweir return ;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir else
248cdf0e10cSrcweir {
249cdf0e10cSrcweir aNodeNames = GetNodeNames(OUString());
250cdf0e10cSrcweir }
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
253cdf0e10cSrcweir OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
254cdf0e10cSrcweir const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
255cdf0e10cSrcweir const OUString* pLabels = aLabels.getConstArray();
256cdf0e10cSrcweir OUString sFoundNode;
257cdf0e10cSrcweir for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir OUString sPrefix(sManufacturer);
260cdf0e10cSrcweir sPrefix += C2U("/");
261cdf0e10cSrcweir sPrefix += pLabels[nLabel];
262cdf0e10cSrcweir sPrefix += C2U("/");
263cdf0e10cSrcweir Sequence<OUString> aProperties(1);
264cdf0e10cSrcweir aProperties.getArray()[0] = sPrefix;
265cdf0e10cSrcweir aProperties.getArray()[0] += C2U("Name");
266cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aProperties);
267cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
268cdf0e10cSrcweir if(pValues[0].hasValue())
269cdf0e10cSrcweir {
270cdf0e10cSrcweir OUString sTmp;
271cdf0e10cSrcweir pValues[0] >>= sTmp;
272cdf0e10cSrcweir if(rType == sTmp)
273cdf0e10cSrcweir {
274cdf0e10cSrcweir sFoundNode = pLabels[nLabel];
275cdf0e10cSrcweir break;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir }
279cdf0e10cSrcweir // if not found - generate a unique node name
280cdf0e10cSrcweir if(!sFoundNode.getLength())
281cdf0e10cSrcweir {
282cdf0e10cSrcweir sal_Int32 nIndex = aLabels.getLength();
283cdf0e10cSrcweir OUString sPrefix(C2U("Label"));
284cdf0e10cSrcweir sFoundNode = sPrefix;
285cdf0e10cSrcweir sFoundNode += OUString::valueOf(nIndex);
286cdf0e10cSrcweir while(lcl_Exists(sFoundNode, aLabels))
287cdf0e10cSrcweir {
288cdf0e10cSrcweir sFoundNode = sPrefix;
289cdf0e10cSrcweir sFoundNode += OUString::valueOf(nIndex++);
290cdf0e10cSrcweir }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir OUString sPrefix(wrapConfigurationElementName(rManufacturer));
293cdf0e10cSrcweir sPrefix += C2U("/");
294cdf0e10cSrcweir sPrefix += sFoundNode;
295cdf0e10cSrcweir sPrefix += C2U("/");
296cdf0e10cSrcweir Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
297cdf0e10cSrcweir Sequence<PropertyValue> aPropValues = lcl_CreateProperties(aPropNames, rRec);
298cdf0e10cSrcweir SetSetProperties(wrapConfigurationElementName(rManufacturer), aPropValues);
299cdf0e10cSrcweir
300cdf0e10cSrcweir }
301cdf0e10cSrcweir
302cdf0e10cSrcweir
303