1*d0626817SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d0626817SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d0626817SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d0626817SAndrew Rist  * distributed with this work for additional information
6*d0626817SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d0626817SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d0626817SAndrew Rist  * "License"); you may not use this file except in compliance
9*d0626817SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d0626817SAndrew Rist  *
11*d0626817SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d0626817SAndrew Rist  *
13*d0626817SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d0626817SAndrew Rist  * software distributed under the License is distributed on an
15*d0626817SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d0626817SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d0626817SAndrew Rist  * specific language governing permissions and limitations
18*d0626817SAndrew Rist  * under the License.
19*d0626817SAndrew Rist  *
20*d0626817SAndrew Rist  *************************************************************/
21*d0626817SAndrew Rist 
22*d0626817SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <vbanewfont.hxx>
25cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
26cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
28cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir using namespace ::ooo::vba;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // ============================================================================
34cdf0e10cSrcweir 
35cdf0e10cSrcweir VbaNewFont::VbaNewFont(
36cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& rxParent,
37cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& rxContext,
38cdf0e10cSrcweir         const uno::Reference< beans::XPropertySet >& rxModelProps ) throw (uno::RuntimeException) :
39cdf0e10cSrcweir     VbaNewFont_BASE( rxParent, rxContext ),
40cdf0e10cSrcweir     mxProps( rxModelProps, uno::UNO_SET_THROW )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // XNewFont attributes
45cdf0e10cSrcweir 
46cdf0e10cSrcweir ::rtl::OUString SAL_CALL VbaNewFont::getName() throw (uno::RuntimeException)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ) );
49cdf0e10cSrcweir     return aAny.get< ::rtl::OUString >();
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir void SAL_CALL VbaNewFont::setName( const ::rtl::OUString& rName ) throw (uno::RuntimeException)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     mxProps->setPropertyValue(
55cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ),
56cdf0e10cSrcweir         uno::Any( rName ) );
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir double SAL_CALL VbaNewFont::getSize() throw (uno::RuntimeException)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ) );
62cdf0e10cSrcweir     return aAny.get< float >();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir void SAL_CALL VbaNewFont::setSize( double fSize ) throw (uno::RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     mxProps->setPropertyValue(
68cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ),
69cdf0e10cSrcweir         uno::Any( static_cast< float >( fSize ) ) );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir sal_Int16 SAL_CALL VbaNewFont::getCharset() throw (uno::RuntimeException)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ) );
75cdf0e10cSrcweir     return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset ) throw (uno::RuntimeException)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
81cdf0e10cSrcweir     if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) )
82cdf0e10cSrcweir         eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) );
83cdf0e10cSrcweir     if( eFontEnc == RTL_TEXTENCODING_DONTKNOW )
84cdf0e10cSrcweir         throw uno::RuntimeException();
85cdf0e10cSrcweir     mxProps->setPropertyValue(
86cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ),
87cdf0e10cSrcweir         uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir sal_Int16 SAL_CALL VbaNewFont::getWeight() throw (uno::RuntimeException)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     return getBold() ? 700 : 400;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight ) throw (uno::RuntimeException)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     setBold( nWeight >= 700 );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getBold() throw (uno::RuntimeException)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ) );
103cdf0e10cSrcweir     return aAny.get< float >() > awt::FontWeight::NORMAL;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir void SAL_CALL VbaNewFont::setBold( sal_Bool bBold ) throw (uno::RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     mxProps->setPropertyValue(
109cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ),
110cdf0e10cSrcweir         uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getItalic() throw (uno::RuntimeException)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ) );
116cdf0e10cSrcweir     return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic ) throw (uno::RuntimeException)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     mxProps->setPropertyValue(
122cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ),
123cdf0e10cSrcweir         uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getUnderline() throw (uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ) );
129cdf0e10cSrcweir     return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline ) throw (uno::RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     mxProps->setPropertyValue(
135cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ),
136cdf0e10cSrcweir         uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir sal_Bool SAL_CALL VbaNewFont::getStrikethrough() throw (uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ) );
142cdf0e10cSrcweir     return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough ) throw (uno::RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     mxProps->setPropertyValue(
148cdf0e10cSrcweir         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ),
149cdf0e10cSrcweir         uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir // XHelperInterface
153cdf0e10cSrcweir 
154cdf0e10cSrcweir VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont, "ooo.vba.msforms.NewFont" )
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // ============================================================================
157