update dev300-m58
[ooovba.git] / svx / source / form / fmcontrollayout.cxx
blobe807f13fcd264127b52f1b4dfa6f217210cad05f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmcontrollayout.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "fmcontrollayout.hxx"
34 #ifndef _SVX_FMPROP_HRC
35 #include "fmprop.hrc"
36 #endif
38 /** === begin UNO includes === **/
39 #include <com/sun/star/form/FormComponentType.hpp>
40 #include <com/sun/star/awt/VisualEffect.hpp>
41 /** === end UNO includes === **/
42 #include <tools/debug.hxx>
43 #include <comphelper/processfactory.hxx>
45 //........................................................................
46 namespace svxform
48 //........................................................................
50 using namespace ::utl;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::awt;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::form;
56 //====================================================================
57 //= ControlLayouter
58 //====================================================================
59 //--------------------------------------------------------------------
60 void ControlLayouter::initializeControlLayout( const Reference< XPropertySet >& _rxControlModel, DocumentType _eDocType )
62 DBG_ASSERT( _rxControlModel.is(), "ControlLayouter::initializeControlLayout: invalid model!" );
63 if ( !_rxControlModel.is() )
64 return;
66 try
68 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo() );
69 if ( !xPSI.is() )
70 // can't do anything
71 return;
73 // the control type
74 sal_Int16 nClassId = FormComponentType::CONTROL;
75 _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
77 // the document type
78 if ( _eDocType == eUnknownDocumentType )
79 _eDocType = DocumentClassification::classifyHostDocument( _rxControlModel.get() );
81 // let's see what the configuration says about the visual effect
82 OConfigurationNode aConfig = getLayoutSettings( _eDocType );
83 Any aVisualEffect = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ) );
84 if ( aVisualEffect.hasValue() )
86 ::rtl::OUString sVisualEffect;
87 OSL_VERIFY( aVisualEffect >>= sVisualEffect );
89 sal_Int16 nVisualEffect = VisualEffect::NONE;
90 if ( sVisualEffect.equalsAscii( "flat" ) )
91 nVisualEffect = VisualEffect::FLAT;
92 else if ( sVisualEffect.equalsAscii( "3D" ) )
93 nVisualEffect = VisualEffect::LOOK3D;
95 if ( xPSI->hasPropertyByName( FM_PROP_BORDER ) )
97 if ( ( nClassId != FormComponentType::COMMANDBUTTON )
98 && ( nClassId != FormComponentType::RADIOBUTTON )
99 && ( nClassId != FormComponentType::CHECKBOX )
100 && ( nClassId != FormComponentType::GROUPBOX )
101 && ( nClassId != FormComponentType::FIXEDTEXT )
102 && ( nClassId != FormComponentType::SCROLLBAR )
103 && ( nClassId != FormComponentType::SPINBUTTON )
106 _rxControlModel->setPropertyValue( FM_PROP_BORDER, makeAny( nVisualEffect ) );
107 if ( ( nVisualEffect == VisualEffect::FLAT )
108 && ( xPSI->hasPropertyByName( FM_PROP_BORDERCOLOR ) )
110 // light gray flat border
111 _rxControlModel->setPropertyValue( FM_PROP_BORDERCOLOR, makeAny( (sal_Int32)0x00C0C0C0 ) );
114 if ( xPSI->hasPropertyByName( FM_PROP_VISUALEFFECT ) )
115 _rxControlModel->setPropertyValue( FM_PROP_VISUALEFFECT, makeAny( nVisualEffect ) );
118 catch( const Exception& )
120 OSL_ENSURE( sal_False, "ControlLayouter::initializeControlLayout: caught an exception!" );
124 //--------------------------------------------------------------------
125 ::utl::OConfigurationNode ControlLayouter::getLayoutSettings( DocumentType _eDocType )
127 ::rtl::OUString sConfigName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Forms/ControlLayout/" ) );
128 sConfigName += DocumentClassification::getModuleIdentifierForDocumentType( _eDocType );
129 return OConfigurationTreeRoot::createWithServiceFactory(
130 ::comphelper::getProcessServiceFactory(), // TODO
131 sConfigName );
134 //--------------------------------------------------------------------
135 bool ControlLayouter::useDynamicBorderColor( DocumentType _eDocType )
137 OConfigurationNode aConfig = getLayoutSettings( _eDocType );
138 Any aDynamicBorderColor = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DynamicBorderColors" ) ) );
139 bool bDynamicBorderColor = false;
140 OSL_VERIFY( aDynamicBorderColor >>= bDynamicBorderColor );
141 return bDynamicBorderColor;
144 //........................................................................
145 } // namespace svxform
146 //........................................................................