merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / itemtype.cxx
blobe94e5d9e2f0e6dcda8d468bd87713ff97c84fcf3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itemtype.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/list.hxx>
36 #include <vcl/outdev.hxx>
37 #include <sfx2/objsh.hxx>
39 #include <svx/svxids.hrc>
42 #include <unotools/intlwrapper.hxx>
43 #include <unotools/localedatawrapper.hxx>
44 #include <svx/xtable.hxx>
45 #include "drawitem.hxx"
46 #include <svx/itemtype.hxx>
48 // -----------------------------------------------------------------------
50 XubString GetMetricText( long nVal, SfxMapUnit eSrcUnit, SfxMapUnit eDestUnit, const IntlWrapper* pIntl )
52 sal_Bool bNeg = sal_False;
53 long nRet = 0;
54 XubString sRet;
56 if ( nVal < 0 )
58 bNeg = sal_True;
59 nVal *= -1;
62 switch ( eDestUnit )
64 case SFX_MAPUNIT_100TH_MM:
65 case SFX_MAPUNIT_10TH_MM:
66 case SFX_MAPUNIT_MM:
67 case SFX_MAPUNIT_CM:
69 nRet = (long)OutputDevice::LogicToLogic(
70 nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_100TH_MM );
72 switch ( eDestUnit )
74 case SFX_MAPUNIT_100TH_MM: nRet *= 1000; break;
75 case SFX_MAPUNIT_10TH_MM: nRet *= 100; break;
76 case SFX_MAPUNIT_MM: nRet *= 10; break;
77 default: ;//prevent warning
79 break;
82 case SFX_MAPUNIT_1000TH_INCH:
83 case SFX_MAPUNIT_100TH_INCH:
84 case SFX_MAPUNIT_10TH_INCH:
85 case SFX_MAPUNIT_INCH:
87 nRet = (long)OutputDevice::LogicToLogic(
88 nVal, (MapUnit)eSrcUnit, (MapUnit)SFX_MAPUNIT_1000TH_INCH );
90 switch ( eDestUnit )
92 case SFX_MAPUNIT_1000TH_INCH: nRet *= 1000; break;
93 case SFX_MAPUNIT_100TH_INCH: nRet *= 100; break;
94 case SFX_MAPUNIT_10TH_INCH: nRet *= 10; break;
95 default: ;//prevent warning
97 break;
100 case SFX_MAPUNIT_POINT:
101 case SFX_MAPUNIT_TWIP:
102 case SFX_MAPUNIT_PIXEL:
103 return String::CreateFromInt32( (long)OutputDevice::LogicToLogic(
104 nVal, (MapUnit)eSrcUnit, (MapUnit)eDestUnit ));
106 default:
107 DBG_ERROR( "not supported mapunit" );
108 return sRet;
111 if ( SFX_MAPUNIT_CM == eDestUnit || SFX_MAPUNIT_INCH == eDestUnit )
113 long nMod = nRet % 10;
115 if ( nMod > 4 )
116 nRet += 10 - nMod;
117 else if ( nMod > 0 )
118 nRet -= nMod;
121 if ( bNeg )
122 sRet += sal_Unicode('-');
124 long nDiff = 1000;
125 for( int nDigits = 4; nDigits; --nDigits, nDiff /= 10 )
127 if ( nRet < nDiff )
128 sRet += sal_Unicode('0');
129 else
130 sRet += String::CreateFromInt32( nRet / nDiff );
131 nRet %= nDiff;
132 if( 4 == nDigits )
134 // DBG_ASSERT(pIntl, "no IntlWrapper* set")
135 if(pIntl)
136 sRet += pIntl->getLocaleData()->getNumDecimalSep();
137 else
138 sRet += ',';
139 if( !nRet )
141 sRet += sal_Unicode('0');
142 break;
145 else if( !nRet )
146 break;
148 return sRet;
151 // -----------------------------------------------------------------------
153 XubString GetSvxString( sal_uInt16 nId )
155 return SVX_RESSTR( nId );
158 #ifndef SVX_LIGHT
160 // -----------------------------------------------------------------------
162 XubString GetColorString( const Color& rCol )
164 const SfxPoolItem* pItem = NULL;
165 XColorTable* pCol = NULL;
166 SfxObjectShell* pSh = SfxObjectShell::Current();
168 if ( pSh )
170 pItem = pSh->GetItem( SID_COLOR_TABLE );
171 if( pItem )
172 pCol = static_cast<const SvxColorTableItem*>(pItem )->GetColorTable();
175 XubString sStr;
177 FASTBOOL bFound = sal_False;
178 ColorData nColData =
179 RGB_COLORDATA( rCol.GetRed(), rCol.GetGreen(), rCol.GetBlue() );
180 sal_uInt16 nColor = 0, nColCount = 16;
182 static ColorData aColAry[] = {
183 COL_BLACK, COL_BLUE, COL_GREEN, COL_CYAN,
184 COL_RED, COL_MAGENTA, COL_BROWN, COL_GRAY,
185 COL_LIGHTGRAY, COL_LIGHTBLUE, COL_LIGHTGREEN, COL_LIGHTCYAN,
186 COL_LIGHTRED, COL_LIGHTMAGENTA, COL_YELLOW, COL_WHITE };
188 while ( !bFound && nColor < nColCount )
190 if ( aColAry[nColor] == nColData )
191 bFound = sal_True;
192 else
193 nColor++;
196 if ( nColor < nColCount )
197 sStr = SVX_RESSTR( RID_SVXITEMS_COLOR_BEGIN + nColor + 1 );
199 if ( !sStr.Len() )
201 sStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "RGB" ));
202 sStr += sal_Unicode('(');
203 sStr += String::CreateFromInt32( rCol.GetRed() );
204 sStr += cpDelim;
205 sStr += String::CreateFromInt32( rCol.GetGreen() );
206 sStr += cpDelim;
207 sStr += String::CreateFromInt32( rCol.GetBlue() );
208 sStr += sal_Unicode(')');
210 return sStr;
213 #endif
215 // -----------------------------------------------------------------------
217 sal_uInt16 GetMetricId( SfxMapUnit eUnit )
219 sal_uInt16 nId = RID_SVXITEMS_METRIC_MM;
221 switch ( eUnit )
223 case SFX_MAPUNIT_100TH_MM:
224 case SFX_MAPUNIT_10TH_MM:
225 case SFX_MAPUNIT_MM:
226 nId = RID_SVXITEMS_METRIC_MM;
227 break;
229 case SFX_MAPUNIT_CM:
230 nId = RID_SVXITEMS_METRIC_CM;
231 break;
233 case SFX_MAPUNIT_1000TH_INCH:
234 case SFX_MAPUNIT_100TH_INCH:
235 case SFX_MAPUNIT_10TH_INCH:
236 case SFX_MAPUNIT_INCH:
237 nId = RID_SVXITEMS_METRIC_INCH;
238 break;
240 case SFX_MAPUNIT_POINT:
241 nId = RID_SVXITEMS_METRIC_POINT;
242 break;
244 case SFX_MAPUNIT_TWIP:
245 nId = RID_SVXITEMS_METRIC_TWIP;
246 break;
248 case SFX_MAPUNIT_PIXEL:
249 nId = RID_SVXITEMS_METRIC_PIXEL;
250 break;
252 default:
253 DBG_ERROR( "not supported mapunit" );
255 return nId;