xref: /AOO41X/main/vbahelper/source/msforms/vbanewfont.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <vbanewfont.hxx>
29*cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
30*cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir using namespace ::com::sun::star;
35*cdf0e10cSrcweir using namespace ::ooo::vba;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir // ============================================================================
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir VbaNewFont::VbaNewFont(
40*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
41*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
42*cdf0e10cSrcweir         const uno::Reference< beans::XPropertySet >& rxModelProps ) throw (uno::RuntimeException) :
43*cdf0e10cSrcweir     VbaNewFont_BASE( rxParent, rxContext ),
44*cdf0e10cSrcweir     mxProps( rxModelProps, uno::UNO_SET_THROW )
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir }
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir // XNewFont attributes
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir ::rtl::OUString SAL_CALL VbaNewFont::getName() throw (uno::RuntimeException)
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ) );
53*cdf0e10cSrcweir     return aAny.get< ::rtl::OUString >();
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setName( const ::rtl::OUString& rName ) throw (uno::RuntimeException)
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     mxProps->setPropertyValue(
59*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ),
60*cdf0e10cSrcweir         uno::Any( rName ) );
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir double SAL_CALL VbaNewFont::getSize() throw (uno::RuntimeException)
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ) );
66*cdf0e10cSrcweir     return aAny.get< float >();
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setSize( double fSize ) throw (uno::RuntimeException)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     mxProps->setPropertyValue(
72*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ),
73*cdf0e10cSrcweir         uno::Any( static_cast< float >( fSize ) ) );
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir sal_Int16 SAL_CALL VbaNewFont::getCharset() throw (uno::RuntimeException)
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ) );
79*cdf0e10cSrcweir     return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) );
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset ) throw (uno::RuntimeException)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
85*cdf0e10cSrcweir     if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) )
86*cdf0e10cSrcweir         eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) );
87*cdf0e10cSrcweir     if( eFontEnc == RTL_TEXTENCODING_DONTKNOW )
88*cdf0e10cSrcweir         throw uno::RuntimeException();
89*cdf0e10cSrcweir     mxProps->setPropertyValue(
90*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ),
91*cdf0e10cSrcweir         uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) );
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir sal_Int16 SAL_CALL VbaNewFont::getWeight() throw (uno::RuntimeException)
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     return getBold() ? 700 : 400;
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight ) throw (uno::RuntimeException)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     setBold( nWeight >= 700 );
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getBold() throw (uno::RuntimeException)
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ) );
107*cdf0e10cSrcweir     return aAny.get< float >() > awt::FontWeight::NORMAL;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setBold( sal_Bool bBold ) throw (uno::RuntimeException)
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     mxProps->setPropertyValue(
113*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ),
114*cdf0e10cSrcweir         uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) );
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getItalic() throw (uno::RuntimeException)
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ) );
120*cdf0e10cSrcweir     return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic ) throw (uno::RuntimeException)
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     mxProps->setPropertyValue(
126*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ),
127*cdf0e10cSrcweir         uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) );
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getUnderline() throw (uno::RuntimeException)
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ) );
133*cdf0e10cSrcweir     return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline ) throw (uno::RuntimeException)
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir     mxProps->setPropertyValue(
139*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ),
140*cdf0e10cSrcweir         uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) );
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getStrikethrough() throw (uno::RuntimeException)
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ) );
146*cdf0e10cSrcweir     return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough ) throw (uno::RuntimeException)
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     mxProps->setPropertyValue(
152*cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ),
153*cdf0e10cSrcweir         uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) );
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir // XHelperInterface
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont, "ooo.vba.msforms.NewFont" )
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir // ============================================================================
161