diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /xmloff/source/forms/handler | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xmloff/source/forms/handler')
-rw-r--r-- | xmloff/source/forms/handler/form_handler_factory.cxx | 65 | ||||
-rw-r--r-- | xmloff/source/forms/handler/vcl_date_handler.cxx | 93 | ||||
-rw-r--r-- | xmloff/source/forms/handler/vcl_date_handler.hxx | 40 | ||||
-rw-r--r-- | xmloff/source/forms/handler/vcl_time_handler.cxx | 96 | ||||
-rw-r--r-- | xmloff/source/forms/handler/vcl_time_handler.hxx | 40 |
5 files changed, 334 insertions, 0 deletions
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 <forms/form_handler_factory.hxx> +#include "vcl_date_handler.hxx" +#include "vcl_time_handler.hxx" +#include <osl/diagnose.h> + +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 <rtl/ustrbuf.hxx> + +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Date.hpp> + +#include <sax/tools/converter.hxx> + +#include <osl/diagnose.h> +#include <tools/date.hxx> + +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 <forms/property_handler.hxx> + +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 <rtl/ustrbuf.hxx> + +#include <com/sun/star/util/Duration.hpp> +#include <com/sun/star/util/Time.hpp> + +#include <sax/tools/converter.hxx> + +#include <osl/diagnose.h> +#include <tools/time.hxx> + +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 <forms/property_handler.hxx> + +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: */ |