summaryrefslogtreecommitdiffstats
path: root/sd/inc/CustomAnimationPreset.hxx
blob: b746b20b7f835ca9653cc2872d26309666629e7c (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* -*- 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 <sal/config.h>

#include <vector>

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

#include "CustomAnimationEffect.hxx"

#include <unordered_map>

namespace sd {

typedef std::unordered_map< OUString, CustomAnimationEffectPtr > EffectsSubTypeMap;
typedef std::unordered_map< OUString, OUString > UStringMap;

class CustomAnimationPreset
{
    friend class CustomAnimationPresets;

public:
    CustomAnimationPreset( const CustomAnimationEffectPtr& pEffect );

    void add( const CustomAnimationEffectPtr& pEffect );

    SD_DLLPUBLIC css::uno::Reference< css::animations::XAnimationNode > create( const OUString& rstrSubType );

    const OUString& getPresetId() const { return maPresetId; }
    const OUString& getLabel() const { return maLabel; }
    double getDuration() const { return mfDuration; }

    std::vector<OUString> getSubTypes();
    std::vector<OUString> getProperties() const;

    bool hasProperty( std::u16string_view rProperty ) const;
    bool isTextOnly() const { return mbIsTextOnly; }

private:
    OUString maPresetId;
    OUString maProperty;
    OUString maLabel;
    OUString maDefaultSubTyp;
    double mfDuration;
    bool mbIsTextOnly;

    EffectsSubTypeMap maSubTypes;
};

typedef std::shared_ptr< CustomAnimationPreset > CustomAnimationPresetPtr;
typedef std::unordered_map<OUString, CustomAnimationPresetPtr> EffectDescriptorMap;
typedef std::vector< CustomAnimationPresetPtr > EffectDescriptorList;

struct PresetCategory
{
    OUString maLabel;
    EffectDescriptorList maEffects;

    PresetCategory( const OUString& rLabel, EffectDescriptorList&& rEffects )
        : maLabel( rLabel ), maEffects( std::move(rEffects) ) {}
};
typedef std::shared_ptr< PresetCategory > PresetCategoryPtr;
typedef std::vector< PresetCategoryPtr > PresetCategoryList;

class SD_DLLPUBLIC CustomAnimationPresets final
{
public:
    SAL_DLLPRIVATE CustomAnimationPresets();
    SAL_DLLPRIVATE ~CustomAnimationPresets();

    /** This method gets presets instance, which is localized
     * for the current user's locale.
    */
    static const CustomAnimationPresets& getCustomAnimationPresets();

    SAL_DLLPRIVATE css::uno::Reference< css::animations::XAnimationNode > getRandomPreset( sal_Int16 nPresetClass ) const;

    CustomAnimationPresetPtr getEffectDescriptor( const OUString& rPresetId ) const;

    SAL_DLLPRIVATE const OUString& getUINameForPresetId( const OUString& rPresetId ) const;
    SAL_DLLPRIVATE const OUString& getUINameForProperty( const OUString& rProperty ) const;

    SAL_DLLPRIVATE const PresetCategoryList& getEntrancePresets() const { return maEntrancePresets; }
    SAL_DLLPRIVATE const PresetCategoryList& getEmphasisPresets() const { return maEmphasisPresets; }
    SAL_DLLPRIVATE const PresetCategoryList& getExitPresets() const { return maExitPresets; }
    SAL_DLLPRIVATE const PresetCategoryList& getMotionPathsPresets() const { return maMotionPathsPresets; }
    SAL_DLLPRIVATE const PresetCategoryList& getMiscPresets() const { return maMiscPresets; }

    SAL_DLLPRIVATE void changePresetSubType( const CustomAnimationEffectPtr& pEffect, const OUString& rPresetSubType ) const;

private:
    SAL_DLLPRIVATE void importEffects();
    SAL_DLLPRIVATE void importResources();

    SAL_DLLPRIVATE void importPresets( const css::uno::Reference< css::lang::XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, PresetCategoryList& rPresetMap  );

    SAL_DLLPRIVATE static const OUString& translateName( const OUString& rId, const UStringMap& rNameMap );

private:
    css::uno::Reference< css::animations::XAnimationNode > mxRootNode;
    EffectDescriptorMap maEffectDescriptorMap;
    UStringMap maEffectNameMap;
    UStringMap maPropertyNameMap;

    PresetCategoryList maEntrancePresets;
    PresetCategoryList maEmphasisPresets;
    PresetCategoryList maExitPresets;
    PresetCategoryList maMotionPathsPresets;
    PresetCategoryList maMiscPresets;

    //! Maps per-language the animation presets.
    SAL_DLLPRIVATE static std::map<OUString, CustomAnimationPresets>  mPresetsMap;
};


css::uno::Reference< css::animations::XAnimationNode > implImportEffects( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceFactory, const OUString& rPath );

void implImportLabels( const css::uno::Reference< css::lang::XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, UStringMap& rStringMap );

}


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