From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/forms/handler/form_handler_factory.cxx | 65 +++++++++++++++ xmloff/source/forms/handler/vcl_date_handler.cxx | 93 +++++++++++++++++++++ xmloff/source/forms/handler/vcl_date_handler.hxx | 40 +++++++++ xmloff/source/forms/handler/vcl_time_handler.cxx | 96 ++++++++++++++++++++++ xmloff/source/forms/handler/vcl_time_handler.hxx | 40 +++++++++ 5 files changed, 334 insertions(+) create mode 100644 xmloff/source/forms/handler/form_handler_factory.cxx create mode 100644 xmloff/source/forms/handler/vcl_date_handler.cxx create mode 100644 xmloff/source/forms/handler/vcl_date_handler.hxx create mode 100644 xmloff/source/forms/handler/vcl_time_handler.cxx create mode 100644 xmloff/source/forms/handler/vcl_time_handler.hxx (limited to 'xmloff/source/forms/handler') diff --git a/xmloff/source/forms/handler/form_handler_factory.cxx b/xmloff/source/forms/handler/form_handler_factory.cxx new file mode 100644 index 000000000..2a943aa82 --- /dev/null +++ b/xmloff/source/forms/handler/form_handler_factory.cxx @@ -0,0 +1,65 @@ +/* -*- 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 . + */ + +#include +#include "vcl_date_handler.hxx" +#include "vcl_time_handler.hxx" +#include + +namespace xmloff +{ + + //= FormHandlerFactory + PPropertyHandler FormHandlerFactory::getFormPropertyHandler( const PropertyId i_propertyId ) + { + PPropertyHandler pHandler; + + switch ( i_propertyId ) + { + case PID_DATE_MIN: + case PID_DATE_MAX: + case PID_DEFAULT_DATE: + case PID_DATE: + { + static PPropertyHandler s_pVCLDateHandler = new VCLDateHandler(); + pHandler = s_pVCLDateHandler; + } + break; + + case PID_TIME_MIN: + case PID_TIME_MAX: + case PID_DEFAULT_TIME: + case PID_TIME: + { + static PPropertyHandler s_pVCLTimeHandler = new VCLTimeHandler(); + pHandler = s_pVCLTimeHandler; + } + break; + + default: + OSL_ENSURE( false, "FormHandlerFactory::getFormPropertyHandler: unknown property ID!" ); + break; + } + + return pHandler; + } + +} // namespace xmloff + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/forms/handler/vcl_date_handler.cxx b/xmloff/source/forms/handler/vcl_date_handler.cxx new file mode 100644 index 000000000..1dfaadd61 --- /dev/null +++ b/xmloff/source/forms/handler/vcl_date_handler.cxx @@ -0,0 +1,93 @@ +/* -*- 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 . + */ + +#include "vcl_date_handler.hxx" + +#include + +#include +#include + +#include + +#include +#include + +namespace xmloff +{ + + using ::com::sun::star::uno::Any; + using ::com::sun::star::util::DateTime; + using ::com::sun::star::util::Date; + + //= VCLDateHandler + VCLDateHandler::VCLDateHandler() + { + } + + OUString VCLDateHandler::getAttributeValue( const Any& i_propertyValue ) const + { + Date aDate; + OSL_VERIFY( i_propertyValue >>= aDate ); + + DateTime aDateTime; // default-inited to 0 + aDateTime.Day = aDate.Day; + aDateTime.Month = aDate.Month; + aDateTime.Year = aDate.Year; + + OUStringBuffer aBuffer; + ::sax::Converter::convertDateTime( aBuffer, aDateTime, nullptr ); + return aBuffer.makeStringAndClear(); + } + + bool VCLDateHandler::getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const + { + DateTime aDateTime; + Date aDate; + if (::sax::Converter::parseDateTime( aDateTime, i_attributeValue )) + { + aDate.Day = aDateTime.Day; + aDate.Month = aDateTime.Month; + aDate.Year = aDateTime.Year; + } + else + { + // compatibility format, before we wrote those values in XML-schema compatible form + sal_Int32 nVCLDate(0); + if (!::sax::Converter::convertNumber(nVCLDate, i_attributeValue)) + { + OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" ); + return false; + } + aDate = ::Date(nVCLDate).GetUNODate(); + } + + const Any aPropertyValue( aDate ); + + OSL_ENSURE( o_propertyValues.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" ); + for ( auto& prop : o_propertyValues ) + { + prop.second = aPropertyValue; + } + return true; + } + +} // namespace xmloff + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/forms/handler/vcl_date_handler.hxx b/xmloff/source/forms/handler/vcl_date_handler.hxx new file mode 100644 index 000000000..626ca4c77 --- /dev/null +++ b/xmloff/source/forms/handler/vcl_date_handler.hxx @@ -0,0 +1,40 @@ +/* -*- 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 . + */ + +#pragma once + +#include + +namespace xmloff +{ + + //= VCLDateHandler + class VCLDateHandler : public PropertyHandlerBase + { + public: + VCLDateHandler(); + + // IPropertyHandler + virtual OUString getAttributeValue( const css::uno::Any& i_propertyValue ) const override; + virtual bool getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const override; + }; + +} // namespace xmloff + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/forms/handler/vcl_time_handler.cxx b/xmloff/source/forms/handler/vcl_time_handler.cxx new file mode 100644 index 000000000..6a8c2cba1 --- /dev/null +++ b/xmloff/source/forms/handler/vcl_time_handler.cxx @@ -0,0 +1,96 @@ +/* -*- 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 . + */ + +#include "vcl_time_handler.hxx" + +#include + +#include +#include + +#include + +#include +#include + +namespace xmloff +{ + + using ::com::sun::star::uno::Any; + using ::com::sun::star::util::Duration; + using ::com::sun::star::util::Time; + + //= VCLTimeHandler + VCLTimeHandler::VCLTimeHandler() + { + } + + OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const + { + css::util::Time aTime; + OSL_VERIFY( i_propertyValue >>= aTime ); + + Duration aDuration; // default-inited to 0 + aDuration.Hours = aTime.Hours; + aDuration.Minutes = aTime.Minutes; + aDuration.Seconds = aTime.Seconds; + aDuration.NanoSeconds = aTime.NanoSeconds; + + OUStringBuffer aBuffer; + ::sax::Converter::convertDuration( aBuffer, aDuration ); + return aBuffer.makeStringAndClear(); + } + + bool VCLTimeHandler::getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const + { + Duration aDuration; + css::util::Time aTime; + if (::sax::Converter::convertDuration( aDuration, i_attributeValue )) + { + aTime = Time(aDuration.NanoSeconds, aDuration.Seconds, + aDuration.Minutes, aDuration.Hours, + false); + } + else + { + // compatibility format, before we wrote those values in XML-schema compatible form + sal_Int64 nVCLTime(0); + if (!::sax::Converter::convertNumber64(nVCLTime, i_attributeValue)) + { + OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" ); + return false; + } + // legacy integer was in centiseconds + nVCLTime *= ::tools::Time::nanoPerCenti; + aTime = ::tools::Time(nVCLTime).GetUNOTime(); + } + + const Any aPropertyValue( aTime ); + + OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" ); + for ( auto& prop : o_propertyValues ) + { + prop.second = aPropertyValue; + } + return true; + } + +} // namespace xmloff + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/forms/handler/vcl_time_handler.hxx b/xmloff/source/forms/handler/vcl_time_handler.hxx new file mode 100644 index 000000000..a5b3b14a9 --- /dev/null +++ b/xmloff/source/forms/handler/vcl_time_handler.hxx @@ -0,0 +1,40 @@ +/* -*- 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 . + */ + +#pragma once + +#include + +namespace xmloff +{ + + //= VCLTimeHandler + class VCLTimeHandler : public PropertyHandlerBase + { + public: + VCLTimeHandler(); + + // IPropertyHandler + virtual OUString getAttributeValue( const css::uno::Any& i_propertyValue ) const override; + virtual bool getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const override; + }; + +} // namespace xmloff + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3