LibreOffice Module vcl (master)  1
unohelp.cxx
Go to the documentation of this file.
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 <vcl/svapp.hxx>
21 #include <vcl/unohelp.hxx>
22 
23 #include <osl/diagnose.h>
24 
26 
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>
34 
35 using namespace ::com::sun::star;
36 
37 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
38 {
39  uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
40  return i18n::BreakIterator::create(xContext);
41 }
42 
43 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
44 {
45  return i18n::CharacterClassification::create( comphelper::getProcessComponentContext() );
46 }
47 
48 void vcl::unohelper::NotifyAccessibleStateEventGlobally( const css::accessibility::AccessibleEventObject& rEventObject )
49 {
50  css::uno::Reference< css::awt::XExtendedToolkit > xExtToolkit( Application::GetVCLToolkit(), uno::UNO_QUERY );
51  if ( !xExtToolkit.is() )
52  return;
53 
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 );
59  else
60  {
61  rEventObject.OldValue >>= nType;
62  if ( nType == css::accessibility::AccessibleStateType::FOCUSED )
63  xExtToolkit->fireFocusLost( rEventObject.Source );
64  }
65 }
66 
68 {
69  if( eWidth == WIDTH_DONTKNOW )
70  return css::awt::FontWidth::DONTKNOW;
71  else if( eWidth == WIDTH_ULTRA_CONDENSED )
72  return css::awt::FontWidth::ULTRACONDENSED;
73  else if( eWidth == WIDTH_EXTRA_CONDENSED )
74  return css::awt::FontWidth::EXTRACONDENSED;
75  else if( eWidth == WIDTH_CONDENSED )
76  return css::awt::FontWidth::CONDENSED;
77  else if( eWidth == WIDTH_SEMI_CONDENSED )
78  return css::awt::FontWidth::SEMICONDENSED;
79  else if( eWidth == WIDTH_NORMAL )
80  return css::awt::FontWidth::NORMAL;
81  else if( eWidth == WIDTH_SEMI_EXPANDED )
82  return css::awt::FontWidth::SEMIEXPANDED;
83  else if( eWidth == WIDTH_EXPANDED )
84  return css::awt::FontWidth::EXPANDED;
85  else if( eWidth == WIDTH_EXTRA_EXPANDED )
86  return css::awt::FontWidth::EXTRAEXPANDED;
87  else if( eWidth == WIDTH_ULTRA_EXPANDED )
88  return css::awt::FontWidth::ULTRAEXPANDED;
89 
90  OSL_FAIL( "Unknown FontWidth" );
91  return css::awt::FontWidth::DONTKNOW;
92 }
93 
95 {
96  if( f <= css::awt::FontWidth::DONTKNOW )
97  return WIDTH_DONTKNOW;
98  else if( f <= css::awt::FontWidth::ULTRACONDENSED )
99  return WIDTH_ULTRA_CONDENSED;
100  else if( f <= css::awt::FontWidth::EXTRACONDENSED )
101  return WIDTH_EXTRA_CONDENSED;
102  else if( f <= css::awt::FontWidth::CONDENSED )
103  return WIDTH_CONDENSED;
104  else if( f <= css::awt::FontWidth::SEMICONDENSED )
105  return WIDTH_SEMI_CONDENSED;
106  else if( f <= css::awt::FontWidth::NORMAL )
107  return WIDTH_NORMAL;
108  else if( f <= css::awt::FontWidth::SEMIEXPANDED )
109  return WIDTH_SEMI_EXPANDED;
110  else if( f <= css::awt::FontWidth::EXPANDED )
111  return WIDTH_EXPANDED;
112  else if( f <= css::awt::FontWidth::EXTRAEXPANDED )
113  return WIDTH_EXTRA_EXPANDED;
114  else if( f <= css::awt::FontWidth::ULTRAEXPANDED )
115  return WIDTH_ULTRA_EXPANDED;
116 
117  OSL_FAIL( "Unknown FontWidth" );
118  return WIDTH_DONTKNOW;
119 }
120 
122 {
123  if( eWeight == WEIGHT_DONTKNOW )
124  return css::awt::FontWeight::DONTKNOW;
125  else if( eWeight == WEIGHT_THIN )
126  return css::awt::FontWeight::THIN;
127  else if( eWeight == WEIGHT_ULTRALIGHT )
128  return css::awt::FontWeight::ULTRALIGHT;
129  else if( eWeight == WEIGHT_LIGHT )
130  return css::awt::FontWeight::LIGHT;
131  else if( eWeight == WEIGHT_SEMILIGHT )
132  return css::awt::FontWeight::SEMILIGHT;
133  else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
134  return css::awt::FontWeight::NORMAL;
135  else if( eWeight == WEIGHT_SEMIBOLD )
136  return css::awt::FontWeight::SEMIBOLD;
137  else if( eWeight == WEIGHT_BOLD )
138  return css::awt::FontWeight::BOLD;
139  else if( eWeight == WEIGHT_ULTRABOLD )
140  return css::awt::FontWeight::ULTRABOLD;
141  else if( eWeight == WEIGHT_BLACK )
142  return css::awt::FontWeight::BLACK;
143 
144  OSL_FAIL( "Unknown FontWeight" );
145  return css::awt::FontWeight::DONTKNOW;
146 }
147 
149 {
150  if( f <= css::awt::FontWeight::DONTKNOW )
151  return WEIGHT_DONTKNOW;
152  else if( f <= css::awt::FontWeight::THIN )
153  return WEIGHT_THIN;
154  else if( f <= css::awt::FontWeight::ULTRALIGHT )
155  return WEIGHT_ULTRALIGHT;
156  else if( f <= css::awt::FontWeight::LIGHT )
157  return WEIGHT_LIGHT;
158  else if( f <= css::awt::FontWeight::SEMILIGHT )
159  return WEIGHT_SEMILIGHT;
160  else if( f <= css::awt::FontWeight::NORMAL )
161  return WEIGHT_NORMAL;
162  else if( f <= css::awt::FontWeight::SEMIBOLD )
163  return WEIGHT_SEMIBOLD;
164  else if( f <= css::awt::FontWeight::BOLD )
165  return WEIGHT_BOLD;
166  else if( f <= css::awt::FontWeight::ULTRABOLD )
167  return WEIGHT_ULTRABOLD;
168  else if( f <= css::awt::FontWeight::BLACK )
169  return WEIGHT_BLACK;
170 
171  OSL_FAIL( "Unknown FontWeight" );
172  return WEIGHT_DONTKNOW;
173 }
174 
175 css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
176 {
177  css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
178  switch (eItalic)
179  {
180  case ITALIC_NONE:
181  eRet = css::awt::FontSlant_NONE;
182  break;
183  case ITALIC_OBLIQUE:
184  eRet = css::awt::FontSlant_OBLIQUE;
185  break;
186  case ITALIC_NORMAL:
187  eRet = css::awt::FontSlant_ITALIC;
188  break;
189  case ITALIC_DONTKNOW:
190  eRet = css::awt::FontSlant_DONTKNOW;
191  break;
193  eRet = css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE;
194  break;
195  }
196  return eRet;
197 }
198 
199 FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
200 {
202  switch (eSlant)
203  {
204  case css::awt::FontSlant_NONE:
205  eRet = ITALIC_NONE;
206  break;
207  case css::awt::FontSlant_OBLIQUE:
208  eRet = ITALIC_OBLIQUE;
209  break;
210  case css::awt::FontSlant_ITALIC:
211  eRet = ITALIC_NORMAL;
212  break;
213  case css::awt::FontSlant_DONTKNOW:
214  eRet = ITALIC_DONTKNOW;
215  break;
216  case css::awt::FontSlant_REVERSE_OBLIQUE:
217  //there is no vcl reverse oblique
218  eRet = ITALIC_OBLIQUE;
219  break;
220  case css::awt::FontSlant_REVERSE_ITALIC:
221  //there is no vcl reverse normal
222  eRet = ITALIC_NORMAL;
223  break;
224  case css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE:
226  break;
227  }
228  return eRet;
229 }
230 
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FontWidth
WEIGHT_THIN
WIDTH_NORMAL
WEIGHT_BLACK
WEIGHT_SEMIBOLD
WIDTH_SEMI_EXPANDED
WEIGHT_LIGHT
WEIGHT_BOLD
VCL_DLLPUBLIC float ConvertFontWidth(FontWidth eWidth)
Definition: unohelp.cxx:67
WIDTH_EXTRA_EXPANDED
WEIGHT_DONTKNOW
WIDTH_ULTRA_EXPANDED
FontItalic_FORCE_EQUAL_SIZE
WEIGHT_SEMILIGHT
ITALIC_OBLIQUE
WEIGHT_MEDIUM
WEIGHT_NORMAL
WEIGHT_ULTRALIGHT
WEIGHT_ULTRABOLD
ITALIC_NONE
WIDTH_CONDENSED
WIDTH_EXPANDED
FontWeight
VCL_DLLPUBLIC css::uno::Reference< css::i18n::XCharacterClassification > CreateCharacterClassification()
Definition: unohelp.cxx:43
ITALIC_NORMAL
WIDTH_DONTKNOW
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
Definition: unohelp.cxx:121
WIDTH_ULTRA_CONDENSED
VCL_DLLPUBLIC css::awt::FontSlant ConvertFontSlant(FontItalic eWeight)
Definition: unohelp.cxx:175
ITALIC_DONTKNOW
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit()
Gets the VCL toolkit.
Definition: svapp.cxx:1448
void(* f)(TrueTypeTable *)
Definition: ttcr.cxx:482
VCL_DLLPUBLIC css::uno::Reference< css::i18n::XBreakIterator > CreateBreakIterator()
Definition: unohelp.cxx:37
WIDTH_SEMI_CONDENSED
WIDTH_EXTRA_CONDENSED
VCL_DLLPUBLIC void NotifyAccessibleStateEventGlobally(const css::accessibility::AccessibleEventObject &rEventObject)
Definition: unohelp.cxx:48
FontItalic