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  {
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
59  {
60  rEventObject.OldValue >>= nType;
61  if ( nType == css::accessibility::AccessibleStateType::FOCUSED )
62  xExtToolkit->fireFocusLost( rEventObject.Source );
63  }
64 
65  }
66 }
67 
69 {
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;
90 
91  OSL_FAIL( "Unknown FontWidth" );
92  return css::awt::FontWidth::DONTKNOW;
93 }
94 
96 {
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;
117 
118  OSL_FAIL( "Unknown FontWidth" );
119  return WIDTH_DONTKNOW;
120 }
121 
123 {
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;
144 
145  OSL_FAIL( "Unknown FontWeight" );
146  return css::awt::FontWeight::DONTKNOW;
147 }
148 
150 {
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;
171 
172  OSL_FAIL( "Unknown FontWeight" );
173  return WEIGHT_DONTKNOW;
174 }
175 
176 css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
177 {
178  css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
179  switch (eItalic)
180  {
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;
194  eRet = css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE;
195  break;
196  }
197  return eRet;
198 }
199 
200 FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
201 {
203  switch (eSlant)
204  {
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:
227  break;
228  }
229  return eRet;
230 }
231 
232 
233 /* 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:68
WIDTH_EXTRA_EXPANDED
WEIGHT_DONTKNOW
WIDTH_ULTRA_EXPANDED
FontItalic_FORCE_EQUAL_SIZE
WEIGHT_SEMILIGHT
ITALIC_OBLIQUE
QPRO_FUNC_TYPE const nType
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:122
WIDTH_ULTRA_CONDENSED
VCL_DLLPUBLIC css::awt::FontSlant ConvertFontSlant(FontItalic eWeight)
Definition: unohelp.cxx:176
ITALIC_DONTKNOW
Reference< XComponentContext > getProcessComponentContext()
static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit()
Gets the VCL toolkit.
Definition: svapp.cxx:1413
void(* f)(TrueTypeTable *)
Definition: ttcr.cxx:466
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