Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / app / unohelp.cxx
blob6d9e6f31abe522406f96bce50d63a86c722b9476
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <osl/diagnose.h>
25 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/i18n/BreakIterator.hpp>
28 #include <com/sun/star/i18n/CharacterClassification.hpp>
29 #include <com/sun/star/awt/FontWeight.hpp>
30 #include <com/sun/star/awt/FontWidth.hpp>
31 #include <com/sun/star/awt/XExtendedToolkit.hpp>
32 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
33 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 using namespace ::com::sun::star;
37 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
39 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
40 return i18n::BreakIterator::create(xContext);
43 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
45 return i18n::CharacterClassification::create( comphelper::getProcessComponentContext() );
48 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const css::accessibility::AccessibleEventObject& rEventObject )
50 css::uno::Reference< css::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY );
51 if ( xExtToolkit.is() )
53 // Only for focus events
54 sal_Int16 nType = css::accessibility::AccessibleStateType::INVALID;
55 rEventObject.NewValue >>= nType;
56 if ( nType == css::accessibility::AccessibleStateType::FOCUSED )
57 xExtToolkit->fireFocusGained( rEventObject.Source );
58 else
60 rEventObject.OldValue >>= nType;
61 if ( nType == css::accessibility::AccessibleStateType::FOCUSED )
62 xExtToolkit->fireFocusLost( rEventObject.Source );
68 float vcl::unohelper::ConvertFontWidth( FontWidth eWidth )
70 if( eWidth == WIDTH_DONTKNOW )
71 return css::awt::FontWidth::DONTKNOW;
72 else if( eWidth == WIDTH_ULTRA_CONDENSED )
73 return css::awt::FontWidth::ULTRACONDENSED;
74 else if( eWidth == WIDTH_EXTRA_CONDENSED )
75 return css::awt::FontWidth::EXTRACONDENSED;
76 else if( eWidth == WIDTH_CONDENSED )
77 return css::awt::FontWidth::CONDENSED;
78 else if( eWidth == WIDTH_SEMI_CONDENSED )
79 return css::awt::FontWidth::SEMICONDENSED;
80 else if( eWidth == WIDTH_NORMAL )
81 return css::awt::FontWidth::NORMAL;
82 else if( eWidth == WIDTH_SEMI_EXPANDED )
83 return css::awt::FontWidth::SEMIEXPANDED;
84 else if( eWidth == WIDTH_EXPANDED )
85 return css::awt::FontWidth::EXPANDED;
86 else if( eWidth == WIDTH_EXTRA_EXPANDED )
87 return css::awt::FontWidth::EXTRAEXPANDED;
88 else if( eWidth == WIDTH_ULTRA_EXPANDED )
89 return css::awt::FontWidth::ULTRAEXPANDED;
91 OSL_FAIL( "Unknown FontWidth" );
92 return css::awt::FontWidth::DONTKNOW;
95 FontWidth vcl::unohelper::ConvertFontWidth( float f )
97 if( f <= css::awt::FontWidth::DONTKNOW )
98 return WIDTH_DONTKNOW;
99 else if( f <= css::awt::FontWidth::ULTRACONDENSED )
100 return WIDTH_ULTRA_CONDENSED;
101 else if( f <= css::awt::FontWidth::EXTRACONDENSED )
102 return WIDTH_EXTRA_CONDENSED;
103 else if( f <= css::awt::FontWidth::CONDENSED )
104 return WIDTH_CONDENSED;
105 else if( f <= css::awt::FontWidth::SEMICONDENSED )
106 return WIDTH_SEMI_CONDENSED;
107 else if( f <= css::awt::FontWidth::NORMAL )
108 return WIDTH_NORMAL;
109 else if( f <= css::awt::FontWidth::SEMIEXPANDED )
110 return WIDTH_SEMI_EXPANDED;
111 else if( f <= css::awt::FontWidth::EXPANDED )
112 return WIDTH_EXPANDED;
113 else if( f <= css::awt::FontWidth::EXTRAEXPANDED )
114 return WIDTH_EXTRA_EXPANDED;
115 else if( f <= css::awt::FontWidth::ULTRAEXPANDED )
116 return WIDTH_ULTRA_EXPANDED;
118 OSL_FAIL( "Unknown FontWidth" );
119 return WIDTH_DONTKNOW;
122 float vcl::unohelper::ConvertFontWeight( FontWeight eWeight )
124 if( eWeight == WEIGHT_DONTKNOW )
125 return css::awt::FontWeight::DONTKNOW;
126 else if( eWeight == WEIGHT_THIN )
127 return css::awt::FontWeight::THIN;
128 else if( eWeight == WEIGHT_ULTRALIGHT )
129 return css::awt::FontWeight::ULTRALIGHT;
130 else if( eWeight == WEIGHT_LIGHT )
131 return css::awt::FontWeight::LIGHT;
132 else if( eWeight == WEIGHT_SEMILIGHT )
133 return css::awt::FontWeight::SEMILIGHT;
134 else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
135 return css::awt::FontWeight::NORMAL;
136 else if( eWeight == WEIGHT_SEMIBOLD )
137 return css::awt::FontWeight::SEMIBOLD;
138 else if( eWeight == WEIGHT_BOLD )
139 return css::awt::FontWeight::BOLD;
140 else if( eWeight == WEIGHT_ULTRABOLD )
141 return css::awt::FontWeight::ULTRABOLD;
142 else if( eWeight == WEIGHT_BLACK )
143 return css::awt::FontWeight::BLACK;
145 OSL_FAIL( "Unknown FontWeight" );
146 return css::awt::FontWeight::DONTKNOW;
149 FontWeight vcl::unohelper::ConvertFontWeight( float f )
151 if( f <= css::awt::FontWeight::DONTKNOW )
152 return WEIGHT_DONTKNOW;
153 else if( f <= css::awt::FontWeight::THIN )
154 return WEIGHT_THIN;
155 else if( f <= css::awt::FontWeight::ULTRALIGHT )
156 return WEIGHT_ULTRALIGHT;
157 else if( f <= css::awt::FontWeight::LIGHT )
158 return WEIGHT_LIGHT;
159 else if( f <= css::awt::FontWeight::SEMILIGHT )
160 return WEIGHT_SEMILIGHT;
161 else if( f <= css::awt::FontWeight::NORMAL )
162 return WEIGHT_NORMAL;
163 else if( f <= css::awt::FontWeight::SEMIBOLD )
164 return WEIGHT_SEMIBOLD;
165 else if( f <= css::awt::FontWeight::BOLD )
166 return WEIGHT_BOLD;
167 else if( f <= css::awt::FontWeight::ULTRABOLD )
168 return WEIGHT_ULTRABOLD;
169 else if( f <= css::awt::FontWeight::BLACK )
170 return WEIGHT_BLACK;
172 OSL_FAIL( "Unknown FontWeight" );
173 return WEIGHT_DONTKNOW;
176 css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
178 css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
179 switch (eItalic)
181 case ITALIC_NONE:
182 eRet = css::awt::FontSlant_NONE;
183 break;
184 case ITALIC_OBLIQUE:
185 eRet = css::awt::FontSlant_OBLIQUE;
186 break;
187 case ITALIC_NORMAL:
188 eRet = css::awt::FontSlant_ITALIC;
189 break;
190 case ITALIC_DONTKNOW:
191 eRet = css::awt::FontSlant_DONTKNOW;
192 break;
193 case FontItalic_FORCE_EQUAL_SIZE:
194 eRet = css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE;
195 break;
197 return eRet;
200 FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
202 FontItalic eRet = ITALIC_DONTKNOW;
203 switch (eSlant)
205 case css::awt::FontSlant_NONE:
206 eRet = ITALIC_NONE;
207 break;
208 case css::awt::FontSlant_OBLIQUE:
209 eRet = ITALIC_OBLIQUE;
210 break;
211 case css::awt::FontSlant_ITALIC:
212 eRet = ITALIC_NORMAL;
213 break;
214 case css::awt::FontSlant_DONTKNOW:
215 eRet = ITALIC_DONTKNOW;
216 break;
217 case css::awt::FontSlant_REVERSE_OBLIQUE:
218 //there is no vcl reverse oblique
219 eRet = ITALIC_OBLIQUE;
220 break;
221 case css::awt::FontSlant_REVERSE_ITALIC:
222 //there is no vcl reverse normal
223 eRet = ITALIC_NORMAL;
224 break;
225 case css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE:
226 eRet = FontItalic_FORCE_EQUAL_SIZE;
227 break;
229 return eRet;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */