summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper/SdtHelper.hxx
blob: cfdd875e7b6bc0b399f13ad008ea93f652aca32a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- 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/.
 */

#ifndef INCLUDED_SDTHELPER_HXX
#define INCLUDED_SDTHELPER_HXX

#include <boost/optional.hpp>

#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <rtl/ustrbuf.hxx>

#include <WriterFilterDllApi.hxx>

namespace com
{
namespace sun
{
namespace star
{
namespace awt
{
struct Size;
class XControlModel;
}
}
}
}

namespace writerfilter
{
namespace dmapper
{

/**
 * Helper to create form controls from w:sdt tokens.
 *
 * w:sdt tokens can't be imported as form fields, as w:sdt supports
 * e.g. date picking as well.
 */
class SdtHelper
{
    DomainMapper_Impl& m_rDM_Impl;

    /// Items of the drop-down control.
    std::vector<OUString> m_aDropDownItems;
    /// Pieces of the default text -- currently used only by the dropdown control.
    OUStringBuffer m_aSdtTexts;
    /// Date ISO string contained in the w:date element, used by the date control.
    OUStringBuffer m_sDate;
    /// Date format string as it comes from the ooxml document.
    OUStringBuffer m_sDateFormat;
    /// Locale string as it comes from the ooxml document.
    OUStringBuffer m_sLocale;
    /// Grab bag to store unsupported SDTs, aiming to save them back on export.
    com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> m_aGrabBag;

    bool m_bHasElements;

    /// Create and append the drawing::XControlShape, containing the various models.
    void createControlShape(com::sun::star::awt::Size aSize, com::sun::star::uno::Reference<com::sun::star::awt::XControlModel>);
    void createControlShape(com::sun::star::awt::Size aSize, com::sun::star::uno::Reference<com::sun::star::awt::XControlModel>,
                            com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> rGrabBag);
public:
    SdtHelper(DomainMapper_Impl& rDM_Impl);
    virtual ~SdtHelper();

    std::vector<OUString>& getDropDownItems();
    OUStringBuffer& getSdtTexts();
    OUStringBuffer& getDate();
    OUStringBuffer& getDateFormat();
    OUStringBuffer& getLocale();
    /// If createControlShape() was ever called.
    bool hasElements();

    /// Create drop-down control from w:sdt's w:dropDownList.
    void createDropDownControl();
    /// Create date control from w:sdt's w:date.
    void createDateControl(OUString& rContentText);

    void appendToInteropGrabBag(const OUString& rName, const css::uno::Any& rValue);
    void appendToInteropGrabBag(com::sun::star::beans::PropertyValue rValue);
    com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> getInteropGrabBagAndClear();
    bool isInteropGrabBagEmpty();
    bool containedInInteropGrabBag(OUString rValueName);
    sal_Int32 getInteropGrabBagSize();
};

} // namespace dmapper
} // namespace writerfilter

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */