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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26
27 // include ---------------------------------------------------------------
28 #include <tools/list.hxx>
29 #include <vcl/outdev.hxx>
30 #include <editeng/editrids.hrc>
31 #include <unotools/intlwrapper.hxx>
32 #include <unotools/localedatawrapper.hxx>
33 #include <editeng/itemtype.hxx>
34 #include <editeng/eerdll.hxx>
35
36 // -----------------------------------------------------------------------
37
GetMetricText(long nVal,SfxMapUnit eSrcUnit,SfxMapUnit eDestUnit,const IntlWrapper * pIntl)38 XubString GetMetricText( long nVal, SfxMapUnit eSrcUnit, SfxMapUnit eDestUnit, const IntlWrapper* pIntl )
39 {
40 sal_Bool bNeg = sal_False;
41 long nRet = 0;
42 XubString sRet;
43
44 if ( nVal < 0 )
45 {
46 bNeg = sal_True;
47 nVal *= -1;
48 }
49
50 switch ( eDestUnit )
51 {
52 case SFX_MAPUNIT_100TH_MM:
53 case SFX_MAPUNIT_10TH_MM:
54 case SFX_MAPUNIT_MM:
55 case SFX_MAPUNIT_CM:
56 {
57 nRet = (long)OutputDevice::LogicToLogic(
58 nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_100TH_MM );
59
60 switch ( eDestUnit )
61 {
62 case SFX_MAPUNIT_100TH_MM: nRet *= 1000; break;
63 case SFX_MAPUNIT_10TH_MM: nRet *= 100; break;
64 case SFX_MAPUNIT_MM: nRet *= 10; break;
65 default: ;//prevent warning
66 }
67 break;
68 }
69
70 case SFX_MAPUNIT_1000TH_INCH:
71 case SFX_MAPUNIT_100TH_INCH:
72 case SFX_MAPUNIT_10TH_INCH:
73 case SFX_MAPUNIT_INCH:
74 {
75 nRet = (long)OutputDevice::LogicToLogic(
76 nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_1000TH_INCH );
77
78 switch ( eDestUnit )
79 {
80 case SFX_MAPUNIT_1000TH_INCH: nRet *= 1000; break;
81 case SFX_MAPUNIT_100TH_INCH: nRet *= 100; break;
82 case SFX_MAPUNIT_10TH_INCH: nRet *= 10; break;
83 default: ;//prevent warning
84 }
85 break;
86 }
87
88 case SFX_MAPUNIT_POINT:
89 case SFX_MAPUNIT_TWIP:
90 case SFX_MAPUNIT_PIXEL:
91 return String::CreateFromInt32( (long)OutputDevice::LogicToLogic(
92 nVal, (MapUnit)eSrcUnit, (MapUnit)eDestUnit ));
93
94 default:
95 DBG_ERROR( "not supported mapunit" );
96 return sRet;
97 }
98
99 if ( SFX_MAPUNIT_CM == eDestUnit || SFX_MAPUNIT_INCH == eDestUnit )
100 {
101 long nMod = nRet % 10;
102
103 if ( nMod > 4 )
104 nRet += 10 - nMod;
105 else if ( nMod > 0 )
106 nRet -= nMod;
107 }
108
109 if ( bNeg )
110 sRet += sal_Unicode('-');
111
112 long nDiff = 1000;
113 for( int nDigits = 4; nDigits; --nDigits, nDiff /= 10 )
114 {
115 if ( nRet < nDiff )
116 sRet += sal_Unicode('0');
117 else
118 sRet += String::CreateFromInt32( nRet / nDiff );
119 nRet %= nDiff;
120 if( 4 == nDigits )
121 {
122 // DBG_ASSERT(pIntl, "no IntlWrapper* set")
123 if(pIntl)
124 sRet += pIntl->getLocaleData()->getNumDecimalSep();
125 else
126 sRet += ',';
127 if( !nRet )
128 {
129 sRet += sal_Unicode('0');
130 break;
131 }
132 }
133 else if( !nRet )
134 break;
135 }
136 return sRet;
137 }
138
139 // -----------------------------------------------------------------------
140
GetSvxString(sal_uInt16 nId)141 XubString GetSvxString( sal_uInt16 nId )
142 {
143 return EE_RESSTR( nId );
144 }
145
146 #ifndef SVX_LIGHT
147
148 // -----------------------------------------------------------------------
149
GetColorString(const Color & rCol)150 XubString GetColorString( const Color& rCol )
151 {
152 XubString sStr;
153
154 FASTBOOL bFound = sal_False;
155 ColorData nColData =
156 RGB_COLORDATA( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
157 sal_uInt16 nColor = 0, nColCount = 16;
158
159 static ColorData aColAry[] = {
160 COL_BLACK, COL_BLUE, COL_GREEN, COL_CYAN,
161 COL_RED, COL_MAGENTA, COL_BROWN, COL_GRAY,
162 COL_LIGHTGRAY, COL_LIGHTBLUE, COL_LIGHTGREEN, COL_LIGHTCYAN,
163 COL_LIGHTRED, COL_LIGHTMAGENTA, COL_YELLOW, COL_WHITE };
164
165 while ( !bFound && nColor < nColCount )
166 {
167 if ( aColAry[nColor] == nColData )
168 bFound = sal_True;
169 else
170 nColor++;
171 }
172
173 if ( nColor < nColCount )
174 sStr = EE_RESSTR( RID_SVXITEMS_COLOR_BEGIN + nColor + 1 );
175
176 if ( !sStr.Len() )
177 {
178 sStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "RGB" ));
179 sStr += sal_Unicode('(');
180 sStr += String::CreateFromInt32( rCol.GetRed() );
181 sStr += cpDelim;
182 sStr += String::CreateFromInt32( rCol.GetGreen() );
183 sStr += cpDelim;
184 sStr += String::CreateFromInt32( rCol.GetBlue() );
185 sStr += sal_Unicode(')');
186 }
187 return sStr;
188 }
189
190 #endif
191
192 // -----------------------------------------------------------------------
193
GetMetricId(SfxMapUnit eUnit)194 sal_uInt16 GetMetricId( SfxMapUnit eUnit )
195 {
196 sal_uInt16 nId = RID_SVXITEMS_METRIC_MM;
197
198 switch ( eUnit )
199 {
200 case SFX_MAPUNIT_100TH_MM:
201 case SFX_MAPUNIT_10TH_MM:
202 case SFX_MAPUNIT_MM:
203 nId = RID_SVXITEMS_METRIC_MM;
204 break;
205
206 case SFX_MAPUNIT_CM:
207 nId = RID_SVXITEMS_METRIC_CM;
208 break;
209
210 case SFX_MAPUNIT_1000TH_INCH:
211 case SFX_MAPUNIT_100TH_INCH:
212 case SFX_MAPUNIT_10TH_INCH:
213 case SFX_MAPUNIT_INCH:
214 nId = RID_SVXITEMS_METRIC_INCH;
215 break;
216
217 case SFX_MAPUNIT_POINT:
218 nId = RID_SVXITEMS_METRIC_POINT;
219 break;
220
221 case SFX_MAPUNIT_TWIP:
222 nId = RID_SVXITEMS_METRIC_TWIP;
223 break;
224
225 case SFX_MAPUNIT_PIXEL:
226 nId = RID_SVXITEMS_METRIC_PIXEL;
227 break;
228
229 default:
230 DBG_ERROR( "not supported mapunit" );
231 }
232 return nId;
233 }
234
235
236