Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "fmcontrollayout.hxx"
31 : : #include "fmprop.hrc"
32 : :
33 : : #include <com/sun/star/form/FormComponentType.hpp>
34 : : #include <com/sun/star/awt/VisualEffect.hpp>
35 : : #include <com/sun/star/i18n/ScriptType.hpp>
36 : : #include <com/sun/star/lang/Locale.hpp>
37 : : #include <com/sun/star/awt/FontDescriptor.hpp>
38 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
39 : : #include <com/sun/star/lang/XServiceInfo.hpp>
40 : : #include <com/sun/star/container/XChild.hpp>
41 : :
42 : : #include <comphelper/processfactory.hxx>
43 : : #include <i18npool/mslangid.hxx>
44 : : #include <unotools/syslocale.hxx>
45 : :
46 : : #include <toolkit/helper/vclunohelper.hxx>
47 : : #include <tools/debug.hxx>
48 : : #include <tools/diagnose_ex.h>
49 : : #include <vcl/outdev.hxx>
50 : :
51 : : //........................................................................
52 : : namespace svxform
53 : : {
54 : : //........................................................................
55 : :
56 : : using namespace ::utl;
57 : : /** === begin UNO using === **/
58 : : using ::com::sun::star::uno::Reference;
59 : : using ::com::sun::star::uno::XInterface;
60 : : using ::com::sun::star::uno::UNO_QUERY;
61 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
62 : : using ::com::sun::star::uno::UNO_SET_THROW;
63 : : using ::com::sun::star::uno::Exception;
64 : : using ::com::sun::star::uno::RuntimeException;
65 : : using ::com::sun::star::uno::Any;
66 : : using ::com::sun::star::uno::makeAny;
67 : : using ::com::sun::star::uno::Sequence;
68 : : using ::com::sun::star::uno::Type;
69 : : using ::com::sun::star::beans::XPropertySet;
70 : : using ::com::sun::star::beans::XPropertySetInfo;
71 : : using ::com::sun::star::lang::Locale;
72 : : using ::com::sun::star::awt::FontDescriptor;
73 : : using ::com::sun::star::style::XStyleFamiliesSupplier;
74 : : using ::com::sun::star::lang::XServiceInfo;
75 : : using ::com::sun::star::container::XNameAccess;
76 : : using ::com::sun::star::container::XChild;
77 : : /** === end UNO using === **/
78 : : namespace FormComponentType = ::com::sun::star::form::FormComponentType;
79 : : namespace VisualEffect = ::com::sun::star::awt::VisualEffect;
80 : : namespace ScriptType = ::com::sun::star::i18n::ScriptType;
81 : :
82 : : //--------------------------------------------------------------------
83 : : namespace
84 : : {
85 : : //....................................................................
86 : : template< class INTERFACE_TYPE >
87 : 0 : Reference< INTERFACE_TYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode )
88 : : {
89 [ # # ]: 0 : Reference< INTERFACE_TYPE > xTypedNode( _rxModelNode, UNO_QUERY );
90 [ # # ]: 0 : if ( xTypedNode.is() )
91 : 0 : return xTypedNode;
92 : : else
93 : : {
94 [ # # ]: 0 : Reference< XChild > xChild( _rxModelNode, UNO_QUERY );
95 [ # # ]: 0 : if ( xChild.is() )
96 [ # # ][ # # ]: 0 : return getTypedModelNode< INTERFACE_TYPE >( xChild->getParent() );
[ # # ]
97 : : else
98 [ # # ]: 0 : return NULL;
99 : : }
100 : : }
101 : :
102 : : //....................................................................
103 : 0 : static bool lcl_getDocumentDefaultStyleAndFamily( const Reference< XInterface >& _rxDocument, ::rtl::OUString& _rFamilyName, ::rtl::OUString& _rStyleName ) SAL_THROW(( Exception ))
104 : : {
105 : 0 : bool bSuccess = true;
106 [ # # ]: 0 : Reference< XServiceInfo > xDocumentSI( _rxDocument, UNO_QUERY );
107 [ # # ]: 0 : if ( xDocumentSI.is() )
108 : : {
109 [ # # ][ # # ]: 0 : if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
110 [ # # ][ # # ]: 0 : || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.WebDocument" ) ) )
[ # # ][ # # ]
[ # # ]
111 : : )
112 : : {
113 [ # # ]: 0 : _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
114 [ # # ]: 0 : _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
115 : : }
116 [ # # ][ # # ]: 0 : else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" ) ) ) )
[ # # ][ # # ]
117 : : {
118 [ # # ]: 0 : _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) );
119 [ # # ]: 0 : _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) );
120 : : }
121 [ # # ][ # # ]: 0 : else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
122 [ # # ][ # # ]: 0 : || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) )
[ # # ][ # # ]
[ # # ]
123 : : )
124 : : {
125 [ # # ]: 0 : _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
126 [ # # ]: 0 : _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "standard" ) );
127 : : }
128 : : else
129 : 0 : bSuccess = false;
130 : : }
131 : 0 : return bSuccess;
132 : : }
133 : :
134 : : //....................................................................
135 : 0 : static void lcl_initializeControlFont( const Reference< XPropertySet >& _rxModel )
136 : : {
137 : : try
138 : : {
139 [ # # ][ # # ]: 0 : Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW );
140 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xStylePSI( xStyle->getPropertySetInfo(), UNO_SET_THROW );
[ # # ]
141 : :
142 : : // determine the script type associated with the system locale
143 [ # # ]: 0 : const SvtSysLocale aSysLocale;
144 [ # # ]: 0 : const LocaleDataWrapper& rSysLocaleData = aSysLocale.GetLocaleData();
145 [ # # ][ # # ]: 0 : const sal_Int16 eSysLocaleScriptType = MsLangId::getScriptType( MsLangId::convertLocaleToLanguage( rSysLocaleData.getLocale() ) );
[ # # ]
146 : :
147 : : // depending on this script type, use the right property from the document's style which controls the
148 : : // default locale for document content
149 : 0 : const sal_Char* pCharLocalePropertyName = "CharLocale";
150 [ # # # # ]: 0 : switch ( eSysLocaleScriptType )
151 : : {
152 : : case ScriptType::LATIN:
153 : : // already defaulted above
154 : 0 : break;
155 : : case ScriptType::ASIAN:
156 : 0 : pCharLocalePropertyName = "CharLocaleAsian";
157 : 0 : break;
158 : : case ScriptType::COMPLEX:
159 : 0 : pCharLocalePropertyName = "CharLocaleComplex";
160 : 0 : break;
161 : : default:
162 : : OSL_FAIL( "lcl_initializeControlFont: unexpected script type for system locale!" );
163 : 0 : break;
164 : : }
165 : :
166 : 0 : ::rtl::OUString sCharLocalePropertyName = ::rtl::OUString::createFromAscii( pCharLocalePropertyName );
167 : 0 : Locale aDocumentCharLocale;
168 [ # # ][ # # ]: 0 : if ( xStylePSI->hasPropertyByName( sCharLocalePropertyName ) )
[ # # ]
169 : : {
170 [ # # ][ # # ]: 0 : OSL_VERIFY( xStyle->getPropertyValue( sCharLocalePropertyName ) >>= aDocumentCharLocale );
[ # # ]
171 : : }
172 : : // fall back to CharLocale property at the style
173 [ # # ]: 0 : if ( aDocumentCharLocale.Language.isEmpty() )
174 : : {
175 [ # # ]: 0 : sCharLocalePropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharLocale" ) );
176 [ # # ][ # # ]: 0 : if ( xStylePSI->hasPropertyByName( sCharLocalePropertyName ) )
[ # # ]
177 : : {
178 [ # # ][ # # ]: 0 : OSL_VERIFY( xStyle->getPropertyValue( sCharLocalePropertyName ) >>= aDocumentCharLocale );
[ # # ]
179 : : }
180 : : }
181 : : // fall back to the system locale
182 [ # # ]: 0 : if ( aDocumentCharLocale.Language.isEmpty() )
183 : : {
184 [ # # ]: 0 : aDocumentCharLocale = rSysLocaleData.getLocale();
185 : : }
186 : :
187 : : // retrieve a default font for this locale, and set it at the control
188 [ # # ][ # # ]: 0 : Font aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_SANS, MsLangId::convertLocaleToLanguage( aDocumentCharLocale ), DEFAULTFONT_FLAGS_ONLYONE );
189 [ # # ]: 0 : FontDescriptor aFontDesc = VCLUnoHelper::CreateFontDescriptor( aFont );
190 [ # # ]: 0 : _rxModel->setPropertyValue(
191 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontDescriptor" ) ),
192 : : makeAny( aFontDesc )
193 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ][ # # ]
194 : : }
195 : 0 : catch( const Exception& )
196 : : {
197 : : DBG_UNHANDLED_EXCEPTION();
198 : : }
199 : 0 : }
200 : : }
201 : :
202 : : //====================================================================
203 : : //= ControlLayouter
204 : : //====================================================================
205 : : //--------------------------------------------------------------------
206 : 0 : Reference< XPropertySet > ControlLayouter::getDefaultDocumentTextStyle( const Reference< XPropertySet >& _rxModel )
207 : : {
208 : : // the style family collection
209 [ # # ][ # # ]: 0 : Reference< XStyleFamiliesSupplier > xSuppStyleFamilies( getTypedModelNode< XStyleFamiliesSupplier >( _rxModel.get() ), UNO_SET_THROW );
[ # # ][ # # ]
210 [ # # ][ # # ]: 0 : Reference< XNameAccess > xStyleFamilies( xSuppStyleFamilies->getStyleFamilies(), UNO_SET_THROW );
[ # # ]
211 : :
212 : : // the names of the family, and the style - depends on the document type we live in
213 : 0 : ::rtl::OUString sFamilyName, sStyleName;
214 [ # # ][ # # ]: 0 : if ( !lcl_getDocumentDefaultStyleAndFamily( xSuppStyleFamilies.get(), sFamilyName, sStyleName ) )
[ # # ][ # # ]
215 [ # # ][ # # ]: 0 : throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown document type!" ) ), NULL );
[ # # ]
216 : :
217 : : // the concrete style
218 [ # # ][ # # ]: 0 : Reference< XNameAccess > xStyleFamily( xStyleFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
[ # # ]
219 [ # # ][ # # ]: 0 : return Reference< XPropertySet >( xStyleFamily->getByName( sStyleName ), UNO_QUERY_THROW );
[ # # ]
220 : : }
221 : :
222 : : //--------------------------------------------------------------------
223 : 0 : void ControlLayouter::initializeControlLayout( const Reference< XPropertySet >& _rxControlModel, DocumentType _eDocType )
224 : : {
225 : : DBG_ASSERT( _rxControlModel.is(), "ControlLayouter::initializeControlLayout: invalid model!" );
226 [ # # ]: 0 : if ( !_rxControlModel.is() )
227 : 0 : return;
228 : :
229 : : try
230 : : {
231 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
[ # # ]
232 : :
233 : : // the control type
234 : 0 : sal_Int16 nClassId = FormComponentType::CONTROL;
235 [ # # ][ # # ]: 0 : _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
[ # # ]
236 : :
237 : : // the document type
238 [ # # ]: 0 : if ( _eDocType == eUnknownDocumentType )
239 [ # # ][ # # ]: 0 : _eDocType = DocumentClassification::classifyHostDocument( _rxControlModel.get() );
[ # # ]
240 : :
241 : : // let's see what the configuration says about the visual effect
242 [ # # ]: 0 : OConfigurationNode aConfig = getLayoutSettings( _eDocType );
243 [ # # ]: 0 : Any aVisualEffect = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ) );
244 [ # # ]: 0 : if ( aVisualEffect.hasValue() )
245 : : {
246 : 0 : ::rtl::OUString sVisualEffect;
247 : 0 : OSL_VERIFY( aVisualEffect >>= sVisualEffect );
248 : :
249 : 0 : sal_Int16 nVisualEffect = VisualEffect::NONE;
250 [ # # ]: 0 : if ( sVisualEffect == "flat" )
251 : 0 : nVisualEffect = VisualEffect::FLAT;
252 [ # # ]: 0 : else if ( sVisualEffect == "3D" )
253 : 0 : nVisualEffect = VisualEffect::LOOK3D;
254 : :
255 [ # # ][ # # ]: 0 : if ( xPSI->hasPropertyByName( FM_PROP_BORDER ) )
[ # # ][ # # ]
256 : : {
257 [ # # ][ # # ]: 0 : if ( ( nClassId != FormComponentType::COMMANDBUTTON )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
258 : : && ( nClassId != FormComponentType::RADIOBUTTON )
259 : : && ( nClassId != FormComponentType::CHECKBOX )
260 : : && ( nClassId != FormComponentType::GROUPBOX )
261 : : && ( nClassId != FormComponentType::FIXEDTEXT )
262 : : && ( nClassId != FormComponentType::SCROLLBAR )
263 : : && ( nClassId != FormComponentType::SPINBUTTON )
264 : : )
265 : : {
266 [ # # ][ # # ]: 0 : _rxControlModel->setPropertyValue( FM_PROP_BORDER, makeAny( nVisualEffect ) );
[ # # ][ # # ]
267 [ # # ][ # # ]: 0 : if ( ( nVisualEffect == VisualEffect::FLAT )
[ # # ]
268 [ # # ][ # # ]: 0 : && ( xPSI->hasPropertyByName( FM_PROP_BORDERCOLOR ) )
[ # # ][ # # ]
[ # # ]
269 : : )
270 : : // light gray flat border
271 [ # # ][ # # ]: 0 : _rxControlModel->setPropertyValue( FM_PROP_BORDERCOLOR, makeAny( (sal_Int32)0x00C0C0C0 ) );
[ # # ][ # # ]
272 : : }
273 : : }
274 [ # # ][ # # ]: 0 : if ( xPSI->hasPropertyByName( FM_PROP_VISUALEFFECT ) )
[ # # ][ # # ]
275 [ # # ][ # # ]: 0 : _rxControlModel->setPropertyValue( FM_PROP_VISUALEFFECT, makeAny( nVisualEffect ) );
[ # # ][ # # ]
276 : : }
277 : :
278 : : // the font (only if we use the document's ref devices for rendering control text, otherwise, the
279 : : // default font of VCL controls is assumed to be fine)
280 [ # # ][ # # ]: 0 : if ( useDocumentReferenceDevice( _eDocType )
[ # # ][ # # ]
281 [ # # ][ # # ]: 0 : && xPSI->hasPropertyByName( FM_PROP_FONT )
[ # # ][ # # ]
[ # # ]
282 : : )
283 [ # # ][ # # ]: 0 : lcl_initializeControlFont( _rxControlModel );
[ # # ]
284 : : }
285 : 0 : catch( const Exception& )
286 : : {
287 : : OSL_FAIL( "ControlLayouter::initializeControlLayout: caught an exception!" );
288 : : }
289 : : }
290 : :
291 : : //--------------------------------------------------------------------
292 : 288 : ::utl::OConfigurationNode ControlLayouter::getLayoutSettings( DocumentType _eDocType )
293 : : {
294 [ + - ]: 288 : ::rtl::OUString sConfigName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Forms/ControlLayout/" ) );
295 [ + - ]: 288 : sConfigName += DocumentClassification::getModuleIdentifierForDocumentType( _eDocType );
296 : : return OConfigurationTreeRoot::createWithServiceFactory(
297 : : ::comphelper::getProcessServiceFactory(), // TODO
298 [ + - ][ + - ]: 288 : sConfigName );
[ + - ][ + - ]
299 : : }
300 : :
301 : : //--------------------------------------------------------------------
302 : 20 : bool ControlLayouter::useDynamicBorderColor( DocumentType _eDocType )
303 : : {
304 [ + - ]: 20 : OConfigurationNode aConfig = getLayoutSettings( _eDocType );
305 [ + - ]: 20 : Any aDynamicBorderColor = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DynamicBorderColors" ) ) );
306 : 20 : bool bDynamicBorderColor = false;
307 : 20 : OSL_VERIFY( aDynamicBorderColor >>= bDynamicBorderColor );
308 [ + - ]: 20 : return bDynamicBorderColor;
309 : : }
310 : :
311 : : //--------------------------------------------------------------------
312 : 271 : bool ControlLayouter::useDocumentReferenceDevice( DocumentType _eDocType )
313 : : {
314 [ + + ]: 271 : if ( _eDocType == eUnknownDocumentType )
315 : 3 : return false;
316 [ + - ]: 268 : OConfigurationNode aConfig = getLayoutSettings( _eDocType );
317 [ + - ]: 268 : Any aUseRefDevice = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentTextMetrics" ) ) );
318 : 268 : bool bUseRefDevice = false;
319 : 268 : OSL_VERIFY( aUseRefDevice >>= bUseRefDevice );
320 [ + - ]: 271 : return bUseRefDevice;
321 : : }
322 : :
323 : : //........................................................................
324 : : } // namespace svxform
325 : : //........................................................................
326 : :
327 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|