summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/inc/anyrefdg.hxx
blob: 9109974a8295467624271a3e7a68c369432802ae (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
/* -*- 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 <sfx2/basedlgs.hxx>
#include <address.hxx>
#include <formula/funcutl.hxx>
#include "IAnyRefDialog.hxx"

#include <memory>

class SfxObjectShell;
class ScDocument;
class ScRangeList;
class ScCompiler;

class ScFormulaReferenceHelper
{
    IAnyRefDialog*      m_pDlg;
    ::std::unique_ptr<ScCompiler>         m_pRefComp;
    formula::RefEdit*       m_pRefEdit;           // active input field
    formula::RefButton*     m_pRefBtn;            // associated button
    weld::Dialog*               m_pDialog;
    SfxBindings*        m_pBindings;
    SCTAB               m_nRefTab;                // used for ShowReference

    OUString            m_sOldDialogText;         // Original title of the dialog window

    bool                m_bEnableColorRef;
    bool                m_bHighlightRef;

    DECL_LINK( ActivateHdl, weld::Widget&, bool );

public:
    ScFormulaReferenceHelper(IAnyRefDialog* _pDlg, SfxBindings* _pBindings);
    ~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE;
    void dispose();

    void                ShowSimpleReference(std::u16string_view rStr);
    void                ShowFormulaReference(const OUString& rStr);
    bool                ParseWithNames( ScRangeList& rRanges, std::u16string_view rStr, const ScDocument& rDoc );
    void                Init();

    void                ShowReference(const OUString& rStr);
    void                ReleaseFocus( formula::RefEdit* pEdit );
    void                HideReference( bool bDoneRefMode = true );
    void                RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton );
    void                RefInputDone( bool bForced );
    void                ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton );

    void                SetDialog(weld::Dialog* pDialog) { m_pDialog = pDialog; }
    void                DoClose( sal_uInt16 nId );
    void                SetDispatcherLock( bool bLock );
    static void         EnableSpreadsheets( bool bFlag = true );
    static void         ViewShellChanged();

    static              void enableInput(bool _bInput);

public:
    static bool         CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
    bool                CanInputDone(bool bForced) const { return m_pRefEdit && (bForced || !m_pRefBtn); }
};

class ScRefHandler : public IAnyRefDialog
{
    weld::DialogController* m_pController;
    bool                 m_bInRefMode;

private:
    ScFormulaReferenceHelper
                        m_aHelper;
    SfxBindings*        m_pMyBindings;

    OUString            m_aDocName;               // document on which the dialog was opened

protected:
    void                disposeRefHandler();
    bool                DoClose( sal_uInt16 nId );

    void                SetDispatcherLock( bool bLock );

    virtual void        RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = nullptr ) override;
    virtual void        RefInputDone( bool bForced = false ) override;

    bool                ParseWithNames( ScRangeList& rRanges, std::u16string_view rStr, const ScDocument& pDoc );

public:
                        ScRefHandler(SfxDialogController &rController, SfxBindings* pB, bool bBindRef);
    virtual             ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override;

    virtual void        SetReference( const ScRange& rRef, ScDocument& rDoc ) override = 0;
    virtual void        AddRefEntry() override;

    virtual bool        IsRefInputMode() const override;
    virtual bool        IsTableLocked() const override;
    virtual bool        IsDocAllowed( SfxObjectShell* pDocSh ) const override;

    virtual void        ShowReference(const OUString& rStr) override;
    virtual void        HideReference( bool bDoneRefMode = true ) override;

    virtual void        ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton ) override;
    virtual void        ReleaseFocus( formula::RefEdit* pEdit ) override;

    virtual void        ViewShellChanged() override;
    void                SwitchToDocument();

    virtual void        SetActive() override = 0;

public:
    bool                EnterRefMode();
    bool                LeaveRefMode();
    static bool CanInputStart( const formula::RefEdit *pEdit )
    {
        return ScFormulaReferenceHelper::CanInputStart( pEdit );
    }
    bool CanInputDone( bool bForced )
    {
        return m_aHelper.CanInputDone( bForced );
    }
};

template<class TBase, bool bBindRef = true>
struct ScRefHdlrControllerImpl : public TBase, public ScRefHandler
{
    enum { UNKNOWN_SLOTID = 0U, SLOTID = UNKNOWN_SLOTID };

    ScRefHdlrControllerImpl(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID, const SfxItemSet* pArg, SfxBindings *pB)
        : TBase(pParent, rUIXMLDescription, rID, pArg)
        , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
    {
    }

    ScRefHdlrControllerImpl(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID)
        : TBase(pB, pCW, pParent, rUIXMLDescription, rID)
        , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
    {
    }
};

struct ScAnyRefDlgController : ScRefHdlrControllerImpl<SfxModelessDialogController>
{
    ScAnyRefDlgController(SfxBindings* rt1, SfxChildWindow* rt2, weld::Window* rt3, const OUString& rt4, const OString& rt5)
        : ScRefHdlrControllerImpl<SfxModelessDialogController>(rt1, rt2, rt3, rt4, rt5)
    {
    }
};

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