1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
21 #include <vcl/unohelp.hxx>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/i18n/BreakIterator.hpp>
29 #include <com/sun/star/i18n/CharacterClassification.hpp>
30 #include <com/sun/star/awt/FontWeight.hpp>
31 #include <com/sun/star/awt/FontWidth.hpp>
32 #include <com/sun/star/awt/XExtendedToolkit.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
34 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 using namespace ::com::sun::star
;
38 uno::Reference
< i18n::XBreakIterator
> vcl::unohelper::CreateBreakIterator()
40 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
41 return i18n::BreakIterator::create(xContext
);
44 uno::Reference
< i18n::XCharacterClassification
> vcl::unohelper::CreateCharacterClassification()
46 return i18n::CharacterClassification::create( comphelper::getProcessComponentContext() );
49 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const css::accessibility::AccessibleEventObject
& rEventObject
)
51 css::uno::Reference
< css::awt::XExtendedToolkit
> xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY
);
52 if ( xExtToolkit
.is() )
54 // Only for focus events
55 sal_Int16 nType
= css::accessibility::AccessibleStateType::INVALID
;
56 rEventObject
.NewValue
>>= nType
;
57 if ( nType
== css::accessibility::AccessibleStateType::FOCUSED
)
58 xExtToolkit
->fireFocusGained( rEventObject
.Source
);
61 rEventObject
.OldValue
>>= nType
;
62 if ( nType
== css::accessibility::AccessibleStateType::FOCUSED
)
63 xExtToolkit
->fireFocusLost( rEventObject
.Source
);
69 float vcl::unohelper::ConvertFontWidth( FontWidth eWidth
)
71 if( eWidth
== WIDTH_DONTKNOW
)
72 return css::awt::FontWidth::DONTKNOW
;
73 else if( eWidth
== WIDTH_ULTRA_CONDENSED
)
74 return css::awt::FontWidth::ULTRACONDENSED
;
75 else if( eWidth
== WIDTH_EXTRA_CONDENSED
)
76 return css::awt::FontWidth::EXTRACONDENSED
;
77 else if( eWidth
== WIDTH_CONDENSED
)
78 return css::awt::FontWidth::CONDENSED
;
79 else if( eWidth
== WIDTH_SEMI_CONDENSED
)
80 return css::awt::FontWidth::SEMICONDENSED
;
81 else if( eWidth
== WIDTH_NORMAL
)
82 return css::awt::FontWidth::NORMAL
;
83 else if( eWidth
== WIDTH_SEMI_EXPANDED
)
84 return css::awt::FontWidth::SEMIEXPANDED
;
85 else if( eWidth
== WIDTH_EXPANDED
)
86 return css::awt::FontWidth::EXPANDED
;
87 else if( eWidth
== WIDTH_EXTRA_EXPANDED
)
88 return css::awt::FontWidth::EXTRAEXPANDED
;
89 else if( eWidth
== WIDTH_ULTRA_EXPANDED
)
90 return css::awt::FontWidth::ULTRAEXPANDED
;
92 OSL_FAIL( "Unknown FontWidth" );
93 return css::awt::FontWidth::DONTKNOW
;
96 FontWidth
vcl::unohelper::ConvertFontWidth( float f
)
98 if( f
<= css::awt::FontWidth::DONTKNOW
)
99 return WIDTH_DONTKNOW
;
100 else if( f
<= css::awt::FontWidth::ULTRACONDENSED
)
101 return WIDTH_ULTRA_CONDENSED
;
102 else if( f
<= css::awt::FontWidth::EXTRACONDENSED
)
103 return WIDTH_EXTRA_CONDENSED
;
104 else if( f
<= css::awt::FontWidth::CONDENSED
)
105 return WIDTH_CONDENSED
;
106 else if( f
<= css::awt::FontWidth::SEMICONDENSED
)
107 return WIDTH_SEMI_CONDENSED
;
108 else if( f
<= css::awt::FontWidth::NORMAL
)
110 else if( f
<= css::awt::FontWidth::SEMIEXPANDED
)
111 return WIDTH_SEMI_EXPANDED
;
112 else if( f
<= css::awt::FontWidth::EXPANDED
)
113 return WIDTH_EXPANDED
;
114 else if( f
<= css::awt::FontWidth::EXTRAEXPANDED
)
115 return WIDTH_EXTRA_EXPANDED
;
116 else if( f
<= css::awt::FontWidth::ULTRAEXPANDED
)
117 return WIDTH_ULTRA_EXPANDED
;
119 OSL_FAIL( "Unknown FontWidth" );
120 return WIDTH_DONTKNOW
;
123 float vcl::unohelper::ConvertFontWeight( FontWeight eWeight
)
125 if( eWeight
== WEIGHT_DONTKNOW
)
126 return css::awt::FontWeight::DONTKNOW
;
127 else if( eWeight
== WEIGHT_THIN
)
128 return css::awt::FontWeight::THIN
;
129 else if( eWeight
== WEIGHT_ULTRALIGHT
)
130 return css::awt::FontWeight::ULTRALIGHT
;
131 else if( eWeight
== WEIGHT_LIGHT
)
132 return css::awt::FontWeight::LIGHT
;
133 else if( eWeight
== WEIGHT_SEMILIGHT
)
134 return css::awt::FontWeight::SEMILIGHT
;
135 else if( ( eWeight
== WEIGHT_NORMAL
) || ( eWeight
== WEIGHT_MEDIUM
) )
136 return css::awt::FontWeight::NORMAL
;
137 else if( eWeight
== WEIGHT_SEMIBOLD
)
138 return css::awt::FontWeight::SEMIBOLD
;
139 else if( eWeight
== WEIGHT_BOLD
)
140 return css::awt::FontWeight::BOLD
;
141 else if( eWeight
== WEIGHT_ULTRABOLD
)
142 return css::awt::FontWeight::ULTRABOLD
;
143 else if( eWeight
== WEIGHT_BLACK
)
144 return css::awt::FontWeight::BLACK
;
146 OSL_FAIL( "Unknown FontWeight" );
147 return css::awt::FontWeight::DONTKNOW
;
150 FontWeight
vcl::unohelper::ConvertFontWeight( float f
)
152 if( f
<= css::awt::FontWeight::DONTKNOW
)
153 return WEIGHT_DONTKNOW
;
154 else if( f
<= css::awt::FontWeight::THIN
)
156 else if( f
<= css::awt::FontWeight::ULTRALIGHT
)
157 return WEIGHT_ULTRALIGHT
;
158 else if( f
<= css::awt::FontWeight::LIGHT
)
160 else if( f
<= css::awt::FontWeight::SEMILIGHT
)
161 return WEIGHT_SEMILIGHT
;
162 else if( f
<= css::awt::FontWeight::NORMAL
)
163 return WEIGHT_NORMAL
;
164 else if( f
<= css::awt::FontWeight::SEMIBOLD
)
165 return WEIGHT_SEMIBOLD
;
166 else if( f
<= css::awt::FontWeight::BOLD
)
168 else if( f
<= css::awt::FontWeight::ULTRABOLD
)
169 return WEIGHT_ULTRABOLD
;
170 else if( f
<= css::awt::FontWeight::BLACK
)
173 OSL_FAIL( "Unknown FontWeight" );
174 return WEIGHT_DONTKNOW
;
177 css::awt::FontSlant
vcl::unohelper::ConvertFontSlant(FontItalic eItalic
)
179 css::awt::FontSlant
eRet(css::awt::FontSlant_DONTKNOW
);
183 eRet
= css::awt::FontSlant_NONE
;
186 eRet
= css::awt::FontSlant_OBLIQUE
;
189 eRet
= css::awt::FontSlant_ITALIC
;
191 case ITALIC_DONTKNOW
:
192 eRet
= css::awt::FontSlant_DONTKNOW
;
194 case FontItalic_FORCE_EQUAL_SIZE
:
195 eRet
= css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE
;
201 FontItalic
vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant
)
203 FontItalic eRet
= ITALIC_DONTKNOW
;
206 case css::awt::FontSlant_NONE
:
209 case css::awt::FontSlant_OBLIQUE
:
210 eRet
= ITALIC_OBLIQUE
;
212 case css::awt::FontSlant_ITALIC
:
213 eRet
= ITALIC_NORMAL
;
215 case css::awt::FontSlant_DONTKNOW
:
216 eRet
= ITALIC_DONTKNOW
;
218 case css::awt::FontSlant_REVERSE_OBLIQUE
:
219 //there is no vcl reverse oblique
220 eRet
= ITALIC_OBLIQUE
;
222 case css::awt::FontSlant_REVERSE_ITALIC
:
223 //there is no vcl reverse normal
224 eRet
= ITALIC_NORMAL
;
226 case css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE
:
227 eRet
= FontItalic_FORCE_EQUAL_SIZE
;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */