1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itemtype.cxx,v $
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
;
64 case SFX_MAPUNIT_100TH_MM
:
65 case SFX_MAPUNIT_10TH_MM
:
69 nRet
= (long)OutputDevice::LogicToLogic(
70 nVal
, (MapUnit
)eSrcUnit
, (MapUnit
)SFX_MAPUNIT_100TH_MM
);
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
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
);
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
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
));
107 DBG_ERROR( "not supported mapunit" );
111 if ( SFX_MAPUNIT_CM
== eDestUnit
|| SFX_MAPUNIT_INCH
== eDestUnit
)
113 long nMod
= nRet
% 10;
122 sRet
+= sal_Unicode('-');
125 for( int nDigits
= 4; nDigits
; --nDigits
, nDiff
/= 10 )
128 sRet
+= sal_Unicode('0');
130 sRet
+= String::CreateFromInt32( nRet
/ nDiff
);
134 // DBG_ASSERT(pIntl, "no IntlWrapper* set")
136 sRet
+= pIntl
->getLocaleData()->getNumDecimalSep();
141 sRet
+= sal_Unicode('0');
151 // -----------------------------------------------------------------------
153 XubString
GetSvxString( sal_uInt16 nId
)
155 return SVX_RESSTR( nId
);
160 // -----------------------------------------------------------------------
162 XubString
GetColorString( const Color
& rCol
)
164 const SfxPoolItem
* pItem
= NULL
;
165 XColorTable
* pCol
= NULL
;
166 SfxObjectShell
* pSh
= SfxObjectShell::Current();
170 pItem
= pSh
->GetItem( SID_COLOR_TABLE
);
172 pCol
= static_cast<const SvxColorTableItem
*>(pItem
)->GetColorTable();
177 FASTBOOL bFound
= sal_False
;
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
)
196 if ( nColor
< nColCount
)
197 sStr
= SVX_RESSTR( RID_SVXITEMS_COLOR_BEGIN
+ nColor
+ 1 );
201 sStr
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "RGB" ));
202 sStr
+= sal_Unicode('(');
203 sStr
+= String::CreateFromInt32( rCol
.GetRed() );
205 sStr
+= String::CreateFromInt32( rCol
.GetGreen() );
207 sStr
+= String::CreateFromInt32( rCol
.GetBlue() );
208 sStr
+= sal_Unicode(')');
215 // -----------------------------------------------------------------------
217 sal_uInt16
GetMetricId( SfxMapUnit eUnit
)
219 sal_uInt16 nId
= RID_SVXITEMS_METRIC_MM
;
223 case SFX_MAPUNIT_100TH_MM
:
224 case SFX_MAPUNIT_10TH_MM
:
226 nId
= RID_SVXITEMS_METRIC_MM
;
230 nId
= RID_SVXITEMS_METRIC_CM
;
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
;
240 case SFX_MAPUNIT_POINT
:
241 nId
= RID_SVXITEMS_METRIC_POINT
;
244 case SFX_MAPUNIT_TWIP
:
245 nId
= RID_SVXITEMS_METRIC_TWIP
;
248 case SFX_MAPUNIT_PIXEL
:
249 nId
= RID_SVXITEMS_METRIC_PIXEL
;
253 DBG_ERROR( "not supported mapunit" );