From b5cd8f9186c023124b25706f65e7608b68c426bd Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 18 Jan 2013 10:06:54 +0200 Subject: fdo#46808, Adapt form::control::FilterControl UNO service to new style The service already existed, it just did not have an IDL file Change-Id: I1ca7ab09491057c1e9c91b5bb6763b84be10b47b --- forms/source/component/Filter.cxx | 114 ++++++++++++--------- forms/source/component/Filter.hxx | 1 + offapi/UnoApi_offapi.mk | 3 + offapi/com/sun/star/form/control/FilterControl.idl | 53 ++++++++++ svx/source/form/formcontroller.cxx | 15 ++- 5 files changed, 128 insertions(+), 58 deletions(-) create mode 100644 offapi/com/sun/star/form/control/FilterControl.idl diff --git a/forms/source/component/Filter.cxx b/forms/source/component/Filter.cxx index 8a64e8bd1903..9afc606ecfeb 100644 --- a/forms/source/component/Filter.cxx +++ b/forms/source/component/Filter.cxx @@ -763,8 +763,16 @@ namespace frm NamedValue aValue; const ::rtl::OUString* pName = NULL; const Any* pValue = NULL; + Reference< XPropertySet > xControlModel; - for ( ; pArguments != pArgumentsEnd; ++pArguments ) + if (aArguments.getLength() == 3 + && (aArguments[0] >>= m_xMessageParent) + && (aArguments[1] >>= m_xFormatter) + && (aArguments[2] >>= xControlModel)) + { + initControlModel(xControlModel); + } + else for ( ; pArguments != pArgumentsEnd; ++pArguments ) { // we recognize PropertyValues and NamedValues if ( *pArguments >>= aProp ) @@ -798,63 +806,71 @@ namespace frm else if ( 0 == pName->compareToAscii( "ControlModel" ) ) { // the control model for which we act as filter control - Reference< XPropertySet > xControlModel; - if ( !(*pValue >>= xControlModel ) || !xControlModel.is() ) + if ( !(*pValue >>= xControlModel ) ) { OSL_FAIL( "OFilterControl::initialize: invalid control model argument!" ); continue; } + initControlModel(xControlModel); + } + } + } - // some properties which are "derived" from the control model we're working for - // ................................................... - // the field - m_xField.clear(); - OSL_ENSURE( ::comphelper::hasProperty( PROPERTY_BOUNDFIELD, xControlModel ), "OFilterControl::initialize: control model needs a bound field property!" ); - xControlModel->getPropertyValue( PROPERTY_BOUNDFIELD ) >>= m_xField; - - // ................................................... - // filter list and control class - m_bFilterList = ::comphelper::hasProperty( PROPERTY_FILTERPROPOSAL, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_FILTERPROPOSAL ) ); - if ( m_bFilterList ) - m_nControlClass = FormComponentType::COMBOBOX; - else - { - sal_Int16 nClassId = ::comphelper::getINT16( xControlModel->getPropertyValue( PROPERTY_CLASSID ) ); - switch (nClassId) + void OFilterControl::initControlModel(Reference< XPropertySet >& xControlModel) + { + if ( !xControlModel.is() ) + { + OSL_FAIL( "OFilterControl::initialize: invalid control model argument!" ); + return; + } + // some properties which are "derived" from the control model we're working for + // ................................................... + // the field + m_xField.clear(); + OSL_ENSURE( ::comphelper::hasProperty( PROPERTY_BOUNDFIELD, xControlModel ), "OFilterControl::initialize: control model needs a bound field property!" ); + xControlModel->getPropertyValue( PROPERTY_BOUNDFIELD ) >>= m_xField; + + // ................................................... + // filter list and control class + m_bFilterList = ::comphelper::hasProperty( PROPERTY_FILTERPROPOSAL, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_FILTERPROPOSAL ) ); + if ( m_bFilterList ) + m_nControlClass = FormComponentType::COMBOBOX; + else + { + sal_Int16 nClassId = ::comphelper::getINT16( xControlModel->getPropertyValue( PROPERTY_CLASSID ) ); + switch (nClassId) + { + case FormComponentType::CHECKBOX: + case FormComponentType::RADIOBUTTON: + case FormComponentType::LISTBOX: + case FormComponentType::COMBOBOX: + m_nControlClass = nClassId; + if ( FormComponentType::LISTBOX == nClassId ) { - case FormComponentType::CHECKBOX: - case FormComponentType::RADIOBUTTON: - case FormComponentType::LISTBOX: - case FormComponentType::COMBOBOX: - m_nControlClass = nClassId; - if ( FormComponentType::LISTBOX == nClassId ) - { - Sequence< ::rtl::OUString > aDisplayItems; - OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aDisplayItems ); - Sequence< ::rtl::OUString > aValueItems; - OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_VALUE_SEQ ) >>= aValueItems ); - OSL_ENSURE( aDisplayItems.getLength() == aValueItems.getLength(), "OFilterControl::initialize: inconsistent item lists!" ); - for ( sal_Int32 i=0; i < ::std::min( aDisplayItems.getLength(), aValueItems.getLength() ); ++i ) - m_aDisplayItemToValueItem[ aDisplayItems[i] ] = aValueItems[i]; - } - break; - default: - m_bMultiLine = ::comphelper::hasProperty( PROPERTY_MULTILINE, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_MULTILINE ) ); - m_nControlClass = FormComponentType::TEXTFIELD; - break; + Sequence< ::rtl::OUString > aDisplayItems; + OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aDisplayItems ); + Sequence< ::rtl::OUString > aValueItems; + OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_VALUE_SEQ ) >>= aValueItems ); + OSL_ENSURE( aDisplayItems.getLength() == aValueItems.getLength(), "OFilterControl::initialize: inconsistent item lists!" ); + for ( sal_Int32 i=0; i < ::std::min( aDisplayItems.getLength(), aValueItems.getLength() ); ++i ) + m_aDisplayItemToValueItem[ aDisplayItems[i] ] = aValueItems[i]; } - } - - // ................................................... - // the connection meta data for the form which we're working for - Reference< XChild > xModel( xControlModel, UNO_QUERY ); - Reference< XRowSet > xForm; - if ( xModel.is() ) - xForm = xForm.query( xModel->getParent() ); - m_xConnection = ::dbtools::getConnection( xForm ); - OSL_ENSURE( m_xConnection.is(), "OFilterControl::initialize: unable to determine the form's connection!" ); + break; + default: + m_bMultiLine = ::comphelper::hasProperty( PROPERTY_MULTILINE, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_MULTILINE ) ); + m_nControlClass = FormComponentType::TEXTFIELD; + break; } } + + // ................................................... + // the connection meta data for the form which we're working for + Reference< XChild > xModel( xControlModel, UNO_QUERY ); + Reference< XRowSet > xForm; + if ( xModel.is() ) + xForm = xForm.query( xModel->getParent() ); + m_xConnection = ::dbtools::getConnection( xForm ); + OSL_ENSURE( m_xConnection.is(), "OFilterControl::initialize: unable to determine the form's connection!" ); } //--------------------------------------------------------------------- diff --git a/forms/source/component/Filter.hxx b/forms/source/component/Filter.hxx index 438776445a3c..cd530478be0d 100644 --- a/forms/source/component/Filter.hxx +++ b/forms/source/component/Filter.hxx @@ -79,6 +79,7 @@ namespace frm private: void implInitFilterList(); + void initControlModel(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xControlModel); public: OFilterControl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB ); diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index a38f4c6697ec..6f848e27a86e 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -129,6 +129,9 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/embed,\ OOoEmbeddedObjectFactory \ StorageFactory \ )) +$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/form/control,\ + FilterControl \ +)) $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/form/inspection,\ DefaultFormComponentInspectorModel \ )) diff --git a/offapi/com/sun/star/form/control/FilterControl.idl b/offapi/com/sun/star/form/control/FilterControl.idl new file mode 100644 index 000000000000..c2b32dcefe9c --- /dev/null +++ b/offapi/com/sun/star/form/control/FilterControl.idl @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __com_sun_star_form_control_FilterControl_idl__ +#define __com_sun_star_form_control_FilterControl_idl__ + +#include +#include +#include +#include + + + module com { module sun { module star { module form { module control { + + +/** describes a check box control which can (but not necessarily has to) be bound to a database field. + +

The model of the control has to support the CheckBox + service.

+ + @see com::sun::star::awt::UnoControl + @see com::sun::star::awt::UnoControlModel +*/ +service FilterControl : com::sun::star::awt::XControl +{ + createWithFormat([in] com::sun::star::awt::XWindow MessageParent, + [in] com::sun::star::util::XNumberFormatter NumberFormatter, + [in] com::sun::star::beans::XPropertySet ControlModel); +}; + + +}; }; }; }; }; + +#endif + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx index 2e2aa6f0950e..8de569787d1b 100644 --- a/svx/source/form/formcontroller.cxx +++ b/svx/source/form/formcontroller.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -3377,15 +3378,11 @@ void FormController::startFiltering() ) { // create a filter control - Sequence< Any > aCreationArgs( 3 ); - aCreationArgs[ 0 ] <<= NamedValue( ::rtl::OUString("MessageParent"), makeAny( VCLUnoHelper::GetInterface( getDialogParentWindow() ) ) ); - aCreationArgs[ 1 ] <<= NamedValue( ::rtl::OUString("NumberFormatter"), makeAny( xFormatter ) ); - aCreationArgs[ 2 ] <<= NamedValue( ::rtl::OUString("ControlModel"), makeAny( xModel ) ); - Reference< XControl > xFilterControl( - m_aContext.createComponentWithArguments( "com.sun.star.form.control.FilterControl", aCreationArgs ), - UNO_QUERY - ); - DBG_ASSERT( xFilterControl.is(), "FormController::startFiltering: could not create a filter control!" ); + Reference< XControl > xFilterControl = form::control::FilterControl::createWithFormat( + m_aContext.getUNOContext(), + VCLUnoHelper::GetInterface( getDialogParentWindow() ), + xFormatter, + xModel); if ( replaceControl( xControl, xFilterControl ) ) { -- cgit v1.2.3