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