summaryrefslogtreecommitdiffstats
path: root/sw/source/core/inc/bookmark.hxx
blob: a9c807063f4fadd48f3275f7de6062d91844c8d8 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/* -*- 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 <cppuhelper/weakref.hxx>
#include <sfx2/Metadatable.hxx>
#include <vcl/keycod.hxx>
#include <memory>
#include <string_view>
#include <com/sun/star/text/XTextContent.hpp>

#include <rtl/ustring.hxx>
#include <osl/diagnose.h>
#include <tools/ref.hxx>
#include <IMark.hxx>
#include <swrect.hxx>
#include "FormFieldButton.hxx"

class SwDoc;
class SwEditWin;
class SwServerObject;
class SvNumberFormatter;
class SfxViewShell;

namespace sw::mark {
        class MarkBase
            : virtual public IMark
        {
        public:
            //getters
            virtual SwPosition& GetMarkPos() const override
                { return *m_pPos1; }
            virtual const OUString& GetName() const override
                { return m_aName; }
            virtual SwPosition& GetOtherMarkPos() const override
            {
                OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
                return *m_pPos2;
            }
            virtual SwPosition& GetMarkStart() const override
            {
                if( !IsExpanded() ) return GetMarkPos( );
                if ( GetMarkPos( ) < GetOtherMarkPos( ) )
                    return GetMarkPos();
                else
                    return GetOtherMarkPos( );
            }
            virtual SwPosition& GetMarkEnd() const override
            {
                if( !IsExpanded() ) return GetMarkPos();
                if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
                    return GetMarkPos( );
                else
                    return GetOtherMarkPos( );
            }

            virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
            virtual bool IsExpanded() const override
                { return static_cast< bool >(m_pPos2); }

            void SetName(const OUString& rName)
                { m_aName = rName; }
            virtual void SetMarkPos(const SwPosition& rNewPos);
            virtual void SetOtherMarkPos(const SwPosition& rNewPos);
            virtual void ClearOtherMarkPos()
                { m_pPos2.reset(); }

            virtual auto InvalidateFrames() -> void;

            virtual OUString ToString( ) const override;
            virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;

            void Swap()
            {
                if(m_pPos2)
                    m_pPos1.swap(m_pPos2);
            }

            virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
            {
            }

            virtual ~MarkBase() override;

            const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
                    { return m_wXBookmark; }
            void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
                    { m_wXBookmark = xBkmk; }

        protected:
            // SwClient
            virtual void SwClientNotify(const SwModify&, const SfxHint&) override;

            MarkBase(const SwPaM& rPaM, const OUString& rName);
            std::unique_ptr<SwPosition> m_pPos1;
            std::unique_ptr<SwPosition> m_pPos2;
            OUString m_aName;
            static OUString GenerateNewName(std::u16string_view rPrefix);

            css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
        };

        class NavigatorReminder final
            : public MarkBase
        {
        public:
            NavigatorReminder(const SwPaM& rPaM);
        };

        class UnoMark final
            : public MarkBase
        {
        public:
            UnoMark(const SwPaM& rPaM);
        };

        class DdeBookmark
            : public MarkBase
        {
        public:
            DdeBookmark(const SwPaM& rPaM);

            const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
            SwServerObject* GetRefObject() { return m_aRefObj.get(); }

            bool IsServer() const { return m_aRefObj.is(); }

            void SetRefObject( SwServerObject* pObj );

            virtual void DeregisterFromDoc(SwDoc& rDoc);
            virtual ~DdeBookmark() override;

        private:
            tools::SvRef<SwServerObject> m_aRefObj;
        };

        class Bookmark
            : virtual public IBookmark
            , public DdeBookmark
            , public ::sfx2::Metadatable
        {
        public:
            Bookmark(const SwPaM& rPaM,
                const vcl::KeyCode& rCode,
                const OUString& rName);
            virtual void InitDoc(SwDoc& io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;

            virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;

            virtual auto InvalidateFrames() -> void override;

            virtual const OUString& GetShortName() const override
                { return m_sShortName; }
            virtual const vcl::KeyCode& GetKeyCode() const override
                { return m_aCode; }
            virtual void SetShortName(const OUString& rShortName) override
                { m_sShortName = rShortName; }
            virtual void SetKeyCode(const vcl::KeyCode& rCode) override
                { m_aCode = rCode; }
            virtual bool IsHidden() const override
                { return m_bHidden; }
            virtual const OUString& GetHideCondition() const override
                { return m_sHideCondition; }
            virtual void Hide(bool rHide) override;
            virtual void SetHideCondition(const OUString& rHideCondition) override;

            // ::sfx2::Metadatable
            virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
            virtual bool IsInClipboard() const override;
            virtual bool IsInUndo() const override;
            virtual bool IsInContent() const override;
            virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;

        private:
            vcl::KeyCode m_aCode;
            OUString m_sShortName;
            bool m_bHidden;
            OUString m_sHideCondition;
        };

        class Fieldmark
            : virtual public IFieldmark
            , public MarkBase
        {
        public:
            Fieldmark(const SwPaM& rPaM);

            virtual OUString GetFieldname() const override
                { return m_aFieldname; }
            virtual OUString GetFieldHelptext() const override
                { return m_aFieldHelptext; }

            virtual IFieldmark::parameter_map_t* GetParameters() override
                { return &m_vParams; }

            virtual const IFieldmark::parameter_map_t* GetParameters() const override
                { return &m_vParams; }

            virtual void SetFieldname(const OUString& aFieldname) override
                { m_aFieldname = aFieldname; }
            virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
                { m_aFieldHelptext = aFieldHelptext; }

            virtual void ReleaseDoc(SwDoc&) = 0;

            void SetMarkStartPos( const SwPosition& rNewStartPos );

            virtual void Invalidate() override;
            virtual OUString ToString() const override;
            virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;

        private:
            OUString m_aFieldname;
            OUString m_aFieldHelptext;
            IFieldmark::parameter_map_t m_vParams;
        };

        class TextFieldmark final
            : public Fieldmark
        {
        public:
            TextFieldmark(const SwPaM& rPaM, const OUString& rName);
            virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
            virtual void ReleaseDoc(SwDoc& rDoc) override;
        };

        // Non text fieldmarks have no content between the start and end marks.
        class NonTextFieldmark
            : public Fieldmark
        {
        public:
            NonTextFieldmark(const SwPaM& rPaM);
            virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
            virtual void ReleaseDoc(SwDoc& rDoc) override;
        };

        /// Fieldmark representing a checkbox form field.
        class CheckboxFieldmark final
            : virtual public ICheckboxFieldmark
            , public NonTextFieldmark
        {
        public:
            CheckboxFieldmark(const SwPaM& rPaM);
            bool IsChecked() const override;
            void SetChecked(bool checked) override;
        };

        /// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
        class FieldmarkWithDropDownButton
            : public NonTextFieldmark
        {
        public:
            FieldmarkWithDropDownButton(const SwPaM& rPaM);
            virtual ~FieldmarkWithDropDownButton() override;

            virtual void ShowButton(SwEditWin* pEditWin) = 0;
            virtual void RemoveButton();

        protected:
            VclPtr<FormFieldButton> m_pButton;
        };

        /// Fieldmark representing a drop-down form field.
        class DropDownFieldmark final
            : public FieldmarkWithDropDownButton
        {
        public:
            DropDownFieldmark(const SwPaM& rPaM);
            virtual ~DropDownFieldmark() override;

            virtual void ShowButton(SwEditWin* pEditWin) override;
            virtual void RemoveButton() override;

            // This method should be called only by the portion so we can now the portion's painting area
            void SetPortionPaintArea(const SwRect& rPortionPaintArea);

            void SendLOKShowMessage(const SfxViewShell* pViewShell);
            static void SendLOKHideMessage(const SfxViewShell* pViewShell);

        private:
            SwRect m_aPortionPaintArea;
        };

        /// Fieldmark representing a date form field.
        /// TODO: this was an SDT in DOCX, which is modelled suboptimally here
        /// as a fieldmark; as it cannot contain paragraph breaks, must be
        /// well-formed XML element, and does not have field separator, it
        /// should be a nesting text attribute similar to SwTextMeta.
        class DateFieldmark final
            : virtual public IDateFieldmark
            , public FieldmarkWithDropDownButton
        {
        public:
            DateFieldmark(const SwPaM& rPaM);
            virtual ~DateFieldmark() override;

            virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
            virtual void ReleaseDoc(SwDoc& rDoc) override;

            virtual void ShowButton(SwEditWin* pEditWin) override;

            void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
            void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);

            virtual OUString GetContent() const override;
            virtual void ReplaceContent(const OUString& sNewContent) override;

            virtual std::pair<bool, double> GetCurrentDate() const override;
            virtual void SetCurrentDate(double fDate) override;
            virtual OUString GetDateInStandardDateFormat(double fDate) const override;

        private:
            OUString GetDateInCurrentDateFormat(double fDate) const;
            std::pair<bool, double> ParseCurrentDateParam() const;
            void InvalidateCurrentDateParam();

            SvNumberFormatter* m_pNumberFormatter;
            sw::DocumentContentOperationsManager* m_pDocumentContentOperationsManager;
            SwRect m_aPaintAreaStart;
            SwRect m_aPaintAreaEnd;
        };

        /// return position of the CH_TXT_ATR_FIELDSEP for rMark
        SwPosition FindFieldSep(IFieldmark const& rMark);

        /// check if rPaM is valid range of new fieldmark
        bool IsFieldmarkOverlap(SwPaM const& rPaM);
}

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