summaryrefslogtreecommitdiff
path: root/include/svx/textchain.hxx
blob: 8c0c6a3b59e648109fd7fef160c9fb6b3a7efbc4 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- 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 INCLUDED_SVX_TEXTCHAIN_HXX
#define INCLUDED_SVX_TEXTCHAIN_HXX

#include <editeng/editdata.hxx>
#include <map>

/*
 * Properties can be accessed and set from a TextChain with:
 * - T TextChain::GetPROPNAME(SdrTextObj *)
 * - void TextChain::SetPROPNAME(SdrTextObj *, T)
 * where T and PROPNAME are respectively type and name of a property.
 *
 * To add a property PROPNAME of type T (and its interface) in TextChain:
 * 1) Add
 *      "DECL_CHAIN_PROP(PROPNAME, T)"
 *    in class ImpChainLinkProperties;
 * 2) Add
 *      "INIT_CHAIN_PROP(PROPNAME, V)"
 *    in constructor of ImpChainLinkProperties below
 *    (V is the initialization value for PROPNAME)
 *
 * 3) Add
 *      "DECL_CHAIN_PROP_INTERFACE(PROPNAME, T)"
 *    in class TextChain (under "public:");
 * 4)  Add
 *       "IMPL_CHAIN_PROP_INTERFACE(PROPNAME, T)"
 *    in file "svx/source/svdraw/textchain.cxx"
*/

#define DECL_CHAIN_PROP(PropName, PropType) \
    PropType a##PropName;

#define INIT_CHAIN_PROP(PropName, PropDefault) \
    a##PropName = (PropDefault);

#define DECL_CHAIN_PROP_INTERFACE(PropName, PropType) \
    PropType const & Get##PropName (const SdrTextObj *); \
    void Set##PropName (const SdrTextObj *, PropType);

#define IMPL_CHAIN_PROP_INTERFACE(PropName, PropType) \
    PropType const & TextChain::Get##PropName (const SdrTextObj *pTarget) { \
        ImpChainLinkProperties *pLinkProperties = GetLinkProperties(pTarget); \
        return pLinkProperties->a##PropName; \
    } \
    void TextChain::Set##PropName (const SdrTextObj *pTarget, PropType aPropParam) \
    { \
        ImpChainLinkProperties *pLinkProperties = GetLinkProperties(pTarget); \
        pLinkProperties->a##PropName = aPropParam; \
    }

/* End Special Properties Macro */


class ImpChainLinkProperties;
class SdrTextObj;
class SdrModel;

namespace rtl {
    class OUString;
}

typedef rtl::OUString ChainLinkId;

enum class CursorChainingEvent
{
    TO_NEXT_LINK,
    TO_PREV_LINK,
    UNCHANGED,
    NULL_EVENT
};

class ImpChainLinkProperties
{
protected:
    friend class TextChain;

    ImpChainLinkProperties() {
        INIT_CHAIN_PROP(NilChainingEvent, false)
        INIT_CHAIN_PROP(CursorEvent, CursorChainingEvent::NULL_EVENT)
        INIT_CHAIN_PROP(PreChainingSel, ESelection(0,0,0,0));
        INIT_CHAIN_PROP(PostChainingSel, ESelection(0,0,0,0));
        INIT_CHAIN_PROP(IsPartOfLastParaInNextLink, false) // XXX: Should come from file
        INIT_CHAIN_PROP(PendingOverflowCheck, false)
        INIT_CHAIN_PROP(SwitchingToNextBox, false)
    }

private:
    // NOTE: Remember to set default value in constructor when adding field
    DECL_CHAIN_PROP(NilChainingEvent, bool)
    DECL_CHAIN_PROP(CursorEvent, CursorChainingEvent)
    DECL_CHAIN_PROP(PreChainingSel, ESelection)
    DECL_CHAIN_PROP(PostChainingSel, ESelection)
    DECL_CHAIN_PROP(IsPartOfLastParaInNextLink, bool)
    DECL_CHAIN_PROP(PendingOverflowCheck, bool)
    DECL_CHAIN_PROP(SwitchingToNextBox, bool)
};


class TextChain
{
public:
    ~TextChain();

    //void AppendLink(SdrTextObj *);
    //bool IsLinkInChain(SdrTextObj *) const;

    //SdrTextObj *GetNextLink(const SdrTextObj *) const;
    //SdrTextObj *GetPrevLink(const SdrTextObj *) const;

    ImpChainLinkProperties *GetLinkProperties(const SdrTextObj *);

    // Specific Link Properties
    DECL_CHAIN_PROP_INTERFACE(CursorEvent, CursorChainingEvent)
    DECL_CHAIN_PROP_INTERFACE(NilChainingEvent, bool)
    DECL_CHAIN_PROP_INTERFACE(PreChainingSel, ESelection)
    DECL_CHAIN_PROP_INTERFACE(PostChainingSel, ESelection)
    // return whether a paragraph is split between this box and the next
    DECL_CHAIN_PROP_INTERFACE(IsPartOfLastParaInNextLink, bool)
    // return whether there is a pending overflow check (usually when we move cursor after an overflow in the prev link)
    DECL_CHAIN_PROP_INTERFACE(PendingOverflowCheck, bool)
    // return whether we are currently moving the cursor to the next box (useful to know whether we should prevent SetOutlinerParaObject invocations in SdrTextObj::EndTextEdit)
    DECL_CHAIN_PROP_INTERFACE(SwitchingToNextBox, bool)

protected:
    TextChain();
    std::map< ChainLinkId, ImpChainLinkProperties *> maLinkPropertiesMap;

private:
    friend class SdrModel;
    //SdrTextObj *impGetNextLink(const SdrTextObj *) const;
    //SdrTextObj *impGetPrevLink(const SdrTextObj *) const;
};

#endif // INCLUDED_SVX_TEXTCHAIN_HXX

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